In some situations you might need to configure and run additional apache httpd instance listening on different port. It is really easy to accomplish using minimal modifications to the standard CentOS apache httpd configuration and init script.
For our example lets assume that we will need to configure apache httpd running on port 8080 without altering original apache running on port 80 (and port 443 if you are utilizing SSL configuration).
- We need to make a copy of original /etc/httpd infrastructure /etc/sysconfig/httpd configuration, and /etc/init.d/httpd startup scripts
# cp -pr /etc/httpd /etc/httpd8080; cp /etc/init.d/httpd /etc/init.d/httpd8080 ; cp /etc/sysconfig/httpd /etc/sysconfig/httpd8080 - We will need to modify control parameters in config file to point new instance toward different ServerRoot and make sure there is no attempt to start SSL subsystem
123456789101112# diff -ruNa /etc/sysconfig/httpd /etc/sysconfig/httpd8080--- /etc/sysconfig/httpd 2013-02-20 15:32:52.000000000 +0100+++ /etc/sysconfig/httpd8080 2013-02-22 01:06:51.000000000 +0100@@ -12,7 +12,7 @@# To pass additional options (for instance, -D definitions) to the# httpd binary at startup, set OPTIONS here.#-OPTIONS="-DSSL"+OPTIONS="-d /etc/httpd8080"## By default, the httpd process is started in the C locale; to
- Next we modify our new init script
1234567891011121314151617181920212223242526272829# diff -ruNa /etc/init.d/httpd /etc/init.d/httpd8080--- /etc/init.d/httpd 2013-01-10 14:23:06.000000000 +0100+++ /etc/init.d/httpd8080 2013-02-22 01:06:21.000000000 +0100@@ -13,8 +13,8 @@# Source function library.. /etc/rc.d/init.d/functions-if [ -f /etc/sysconfig/httpd ]; then- . /etc/sysconfig/httpd+if [ -f /etc/sysconfig/httpd8080 ]; then+ . /etc/sysconfig/httpd8080fi# Start httpd in the C locale by default.@@ -29,11 +29,11 @@# work correctly with a thread-based MPM; notably PHP will refuse to start.# Path to the apachectl script, server binary, and short-form for messages.-apachectl=/usr/sbin/apachectl+apachectl=/usr/sbin/apachectl8080httpd=${HTTPD-/usr/sbin/httpd}-prog=httpd-pidfile=${PIDFILE-/var/run/httpd.pid}-lockfile=${LOCKFILE-/var/lock/subsys/httpd}+prog=httpd8080+pidfile=${PIDFILE-/var/run/httpd8080.pid}+lockfile=${LOCKFILE-/var/lock/subsys/httpd8080}RETVAL=0STOP_TIMEOUT=${STOP_TIMEOUT-10}
If you read it carefully you have probably noticed /usr/sbin/apachectl8080 in there. It’s much too important helper script to leave our new instance without – I will get to that in a little while.
- Now it’s time to fix apache httpd configuration to match init script.
12345678910111213141516171819202122232425262728293031323334353637# diff -ruNa /etc/httpd/conf/httpd.conf /etc/httpd8080/conf/httpd.conf--- /etc/httpd/conf/httpd.conf 2013-02-21 13:37:33.000000000 +0100+++ /etc/httpd8080/conf/httpd.conf 2013-02-22 01:11:00.000000000 +0100@@ -54,13 +54,13 @@## Do NOT add a slash at the end of the directory path.#-ServerRoot "/etc/httpd"+ServerRoot "/etc/httpd8080"## PidFile: The file in which the server should record its process# identification number when it starts.#-PidFile run/httpd.pid+PidFile run/httpd8080.pid## Timeout: The number of seconds before receives and sends time out.@@ -133,7 +133,7 @@# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)##Listen 12.34.56.78:80-Listen 80+Listen 8080## Dynamic Shared Object (DSO) Support@@ -471,7 +471,7 @@# logged here. If you *do* define an error logfile for a <VirtualHost># container, that host's errors will be logged there and not here.#-ErrorLog logs/error_log+ErrorLog logs/8080error_log## LogLevel: Control the number of messages logged to the error_log.
As you can see there are very few differences – ServerRoot directive, pid file name, port number and log file name (as the rule I have default access_log disabled, but if you use it then make sure that each apache httpd instance uses it’s own log). Also make sure you don’t have Virtual Hosts configured for port 80 or 443 in separate config files included from /etc/httpd8080/conf.d
- And the last but equially important – separate version of apachectl script to manage our apache instance
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# diff -ruNa /usr/sbin/apachectl /usr/sbin/apachectl8080 --- /usr/sbin/apachectl 2013-01-10 14:18:49.000000000 +0100 +++ /usr/sbin/apachectl8080 2013-02-22 14:52:01.000000000 +0100 @@ -55,11 +55,11 @@ # # the URL to your server's mod_status status page. If you do not # have one, then status and fullstatus will not work. -STATUSURL="http://localhost:80/server-status" +STATUSURL="http://localhost:8080/server-status" # Source /etc/sysconfig/httpd for $HTTPD setting, etc. -if [ -r /etc/sysconfig/httpd ]; then - . /etc/sysconfig/httpd +if [ -r /etc/sysconfig/httpd8080 ]; then + . /etc/sysconfig/httpd8080 fi # |
Unfortunately you will have to manually edit port number for the STATUSURL variable.
Now you are ready to use additional apache httpd. In order to add new init script to startup sequence use chkconfig:
chkconfig --level 2345 httpd8080 on
Thanks a lot!!