Centos: How to run additional apache instance on different port

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).

  1. 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
  2. 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

  3. Next we modify our new init script

    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.

  4. Now it’s time to fix apache httpd configuration to match init script.

    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

  5. And the last but equially important – separate version of apachectl script to manage our apache instance
  6. 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

  1. Thanks a lot!!

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">