I need to set up several independent instances of apache2 listening on different ip address/port combinations. I found an article that detailed a few steps on how to accomplish this with a single installation and changing various scripting values.
Arnold’s wor(l)ds » Running multiple instances of Apache
I believe I can modify this tutorial for opensuse and use it to start, stop and restart the apache2 instances independently.
I am planning on rewriting the apache2 daemon script /etc/init.d/apache2 so that it takes an extra argument that is the instance name. For example:
$ /etc/init.d/apache2 INSTANCE_NAME start
This command would start the apache2 daemon for the INSTANCE_NAME instance. Each instance will have it’s own log directory, pid, config dir, etc. These settings will need to be set in the /etc/init.d/apache2 script. Another script that may need to be changed is the apache2ctl script located in /usr/sbin. I believe that if I add an extra argument to this script I can specify the correct apache2 pid and log files as well.
My question for the community is, does anyone see a problem with my proposed solution? I am not a veteran apache2 admin and any tips would be greatly appreciated. Thanks in advance!
What is it you need to do with multiple instances that you can’t do with virtual hosts (either name based or IP address based)?
As a standard, rc services have same set of parameters:
Several utilities rely on this pattern and may invoke them that way.
So, if you want to add additional parameters, you should follow these rules:
(1) The scripts should run as before if someone does not pass the additional parameters. That means, it must assume reasonable default values for the new parameters. You know, most installations use single instance.
(2) Additional parameters must be added after the existing parameters (not before). This is because of the fact that the existing parameters are positional.
The reason I need multiple instances is because I wish to isolate various sites that I am hosting on a production server. When one site needs maintenance and the apache2 daemon needs to be restarted I don’t want to affect the other production sites whatsoever. I also need to set up a few SSL sites and I believe that each site with an SSL needs its own IP address. I need to do some more research on this but if you have any insight for me I would appreciate it!
Ah! That makes perfect sense. I should write the scripts so that the option that specifies an instance can be omitted and the script will still work. For example, the following command will start all apache2 instances:
Or if you want to restart a single instance of apache2:
/etc/init.d/apache2 restart INSTANCE_NAME
Thanks for the tip!
If your idea is to run multiple instances to serve multiple production sites, don’t forget that you have to run them all on different ports.
Yes, I have multiple static IP’s and multiple interfaces I will be assigning the sites to.
Apache has no problem listening on multiple IP addresses at the same time and having a cert for each IP.
You’re right about restarting the service affecting all sites at once, but generally you just do a reload of the service, not a restart, which only takes a fraction of a second. I’m not sure what maintenance you need to do but there are ways to disable a site using a couple of lines in the config while it’s being upgraded. For an example see the instructions here:
Upgrading Mahara - Mahara Wiki
Of course you should really be doing your testing on a different Apache instance if it’s a production server.
All in all easier than managing multiple instances, which is certainly possible if you have the scripts for it.
You could just use a different config file for each instance. You will need to make sure that you give each instance it’s own location for logs and the pid file. When you run apachectl it by default uses httpd.conf if you start apache using apachectl -f /“path”/httpd2.conf -k start. you can use you second config file.