Apache Reverse Proxy

A reverse proxy is a type of proxy server that retrieves resources on behalf of a client from one or more servers.

In our case we have the server 192.168.10.20 and 192.168.10.30 in the DMZ that need to be accessed by http://www.company1.com/ and http://www.company2.com/ from the WAN

Installing Apache

Before installing Apache2 maybe we need to update the sources as follow:

$ sudo apt-get update

Now we can launch the installation:

$ sudo apt-get install apache2

And the apache server is installed!

Enabling the proxy module

There are two different ways of making reverse proxy, the mod proxy and the rewrite rule.
In our case, we are going to use mod_proxy.
After installing the Apache server we would like to activate the proxy module like this:

<IfModule mod_proxy.c>
#turning ProxyRequests on and allowing proxying from all may allow
#spammers to use your proxy to send email.
ProxyRequests Off
<Proxy *>
AddDefaultCharset off
Order deny,allow
Allow from all
</Proxy>
# Enable/disable the handling of HTTP/1.1 "Via:" headers.
# ("Full" adds the server version; "Block" removes all outgoing Via: headers)
# Set to one of: Off | On | Full | Block
ProxyVia On
</IfModule>

Now we can set the command to enable the reverse proxy and restart the apache server

$ a2enmod proxy
$ a2enmod proxy_http
$ /etc/init.d/apache2 restart

In case we have errors, we can check the Apache log file in /var/log/apache2/

First we need to change the zone file on the DNS server and add a record Type A for our domain : company1.com and company2.com to point out on our proxy server’s IP address. (let’s say a.a.a.a)

Enabling configuration

$ sudo a2ensite company.com
$ sudo /etc/init.d/apache2 restart

Bonus

If you want to redirect the URL of the same domain to another server, lets take the example of company1.
http://www.company1.com/ is redirected to the server 192.168.10.20
But if you want http://www.company1.com/blog/ to be directed to the server 192.168.10.50
Follow this config file