Running multiple sites or multiple servers over a single IP, Using apache reverse proxy

PRIYANSHU JAIN
2 min readJan 31, 2018

--

As an Engineer or developer I play around things, today I figured out how to setup multiple sites over a single IP, I’ve only one GCP instance and a single public IP but I wanted to run two sites over an IP so for this I used virtual hosts, I filter the web traffic by hostname and then provide mod_proxy directives to hand off the requests to other internal web servers running on different ports (for example In my case they are running on port 8080 and port 3000). Options like ProxyPreserveHost allow you to hand off the original hostname in the request so you can further use hostname filtering on the servers.

Routing request to mutiple servers using apache reverse proxy

Here is a sample method to do this:

If you want to use default config for one of your site then you can copy default config to your site

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/SITE_NAME.conf

or

create config for your site

sudo nano /etc/apache2/sites-available/SITE_NAME.conf

here is a config for site1 and site2:

Enable mod_proxy_http :

sudo a2enmod proxysudo a2enmod proxy_httpsudo service apache2 restart

disable default config if it’s there:

sudo a2dissite 000-default.conf

now enable both sites:

sudo a2ensite /etc/apache2/sites-available/site1.confsudo a2ensite /etc/apache2/sites-available/site2.conf

this will create a symlink of .conf file into /etc/apache2/sites-enabled, as in sites-enabled all the enabled sites will be there and the same config will be served by apache.

and finally reload apache service:

sudo service apache2 reload

Now you will be able to access both sites via http on remote clients.

--

--