Reverse proxy of virtual hosts with apache 2

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>

6 Comments

  1. Lone said:

    I’m trying to implement this and when I browse to the Proxy Server, I only get the default internal website. It’s almost as if the Proxy is passing the IP address to the internal server instead of the Virtual Host name. Is there a good way to debug this? I’ve had the Virtual Host Web server running for a long time now. I’m trying to implement this so that I can split some of the Virtual Hosts among a couple different web servers. Any help would be great. Thanks.

  2. Raskas’ blog » Blog Archive » Reverse proxy with an internal https server said:

    [...] my Reverse proxy of virtual hosts with apache 2 blog entry I showed how you can configure a reverse proxy. The only limitation is that the internal [...]

  3. Tegan said:

    I have the same problem. I have multiple virtual hosts on one machine and it seems to go to the default.

  4. Larry Dalton said:

    This made my day. Kept searching for the right config and this was it. I put the domains in my /etc/hosts file and it forwards to the other systems behind my router. Slick.

    Larry

  5. Stefan Radman said:

    That was exactly what I was looking for. Thanks a bunch.
    It just needs “ProxyPreserveHost On” to work with several backend servers on the same machine.
    That directive is needed to make the proxy pass the original “Host:” header to the backend server.

    Stefan

  6. Apache – 用Apache2 虚拟主机做反向代理 – My HowTo said:

    [...] http://www.raskas.be/blog/2006/04/21/reverse-proxy-of-virtual-hosts-with-apache-2/ [...]