23/11/2024
Centos 8 multiple httpd instances
This is an old post I had in draft since… I don’t know, maybe years.
Anyway, CentOS 8 is old and out of support, but still I think running several instances of Apache httpd server through systemd can be useful today in other modern Linux distributions, so I think it’s time to clean up the drafts and publish it.
—————————————————
Recently a customer asked me to setup a webdav access to a vm to change some files inside a couple of java web applications deployed on a Tomcat instance.
My first choice was to configure the webdav servlet already available with Tomcat, which sounds like a nice and elegant solution, but that went wrong because webdav http methods were blocked by some Spring waf protection, and change the java applications for that was not an option (for various reasons I will not explain but not technical ones).
At this point I thought to create a new virtualhost for the webdav access, but in that case file ownership would be a problem, and running the frontend webserver with write permission on all the applications resouces was not a good idea.
The solution was simple, setup a new webserver running as tomcat user (Tomcat file owner) on a different port (and also only available on lan) but I found no documentation with some of the latest distros using systemd.
Yes I know, I could install nginx or another webserver, but running a new Apache configuration felt much more elegant to me.
First of all, create a new httpd systemd unit copying the old one with a new name
cp -v /usr/lib/systemd/system/httpd.service /usr/lib/systemd/system/httpd-dav.service
Copy the main httpd config file for the new webserver
cp -v /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd-dav.conf
Enable the new systemd unit to start at boot
systemctl enable httpd-dav.service
To check if it’s ok run this
systemctl list-unit-files | grep httpd-dav
Now you must edit the new systemd unit to use the new httpd-dav.conf file
systemctl edit httpd-dav.service
…and add this
[Service] Environment=OPTIONS="-f /etc/httpd/conf/httpd-dav.conf"
Now you must edit the new httpd-dav.conf changing some basic directives to not overlap the main Apache configuration:
In my case I changed Listen PidFile, User, Group, ErrorLog, CustomLog, I removed “IncludeOptional conf.d/*.conf” and added a new virtualhost with mod_dav active, basic authentication, etc etc…
Adjust your Apache configurations as you need, but at least you have to change the Listen and PidFile directives to avoid conflicts with the other httpd process.
When you’re ready you only have to start it with
systemctd start httpd-dav.service
I hope this can be helpful.