Archive for April 21st, 2006

Reverse proxy of virtual hosts with apache 2

Posted in Linux SysAdmin on April 21st, 2006 by Johan Huysmans – 6 Comments

Ok, here is the situation:
We have a gateway connected to the internal network and the internet. We have one public ip and several dns names. The dns names *.x-tend.be are linked to the public ip address of the gateway, *.internal.x-tend.be are linked to the servers on the internal network.

This is what we want to accomplish:
You browse to a url from the internet and you get the website from the server located on the internal network. When you browse to another url, you get a different website from the same server on the internal network.

The first step is to configure the internal server. It is a normal virtual host configuration.
red.internal.x-tend.be and blue.internal.x-tend.be are linked to the same server. But you will get a different webpage.

The second step is the configuration of the gateway. It is also based on a virtual host configuration.
red.x-tend.be and blue.x-tend.be are linked to the gateway, and each has his virtual host. In that virtual host declaration you say it has to reverse-proxy to red.internal.x-tend.be and blue.internal.x-tend.be.

A basic configuration on the gateway can look like this:

NameVirtualHost *:80

<VirtualHost *:80>
     ServerName blue.x-tend.be

     ProxyRequests off
     ProxyPass / http://blue.internal.x-tend.be/
     ProxyPassReverse / http://blue.internal.x-tend.be/
</VirtualHost>

<VirtualHost *:80>
     ServerName red.x-tend.be

     ProxyRequests off
     ProxyPass / http://red.internal.x-tend.be/
     ProxyPassReverse / http://red.internal.x-tend.be/
</VirtualHost>