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>
May 12th, 2006
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.
May 15th, 2007
[...] 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 [...]
July 24th, 2007
I have the same problem. I have multiple virtual hosts on one machine and it seems to go to the default.
September 2nd, 2007
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
May 21st, 2008
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
September 18th, 2010
[...] http://www.raskas.be/blog/2006/04/21/reverse-proxy-of-virtual-hosts-with-apache-2/ [...]