Apache proxy virtual host on backend server

Solution 1:

How about modifying your front end settings like this? And you don't need virtual host settings in backend.

<VirtualHost *:80>
    ServerName dev.example.com
    ProxyPass / http://192.168.144.100:80/
    ProxyPassReverse / http://192.168.144.100:80/
</VirtualHost>

<VirtualHost *:80>
    ServerName sandbox.example.com
    ProxyPass / http://192.168.144.100:80/example.com/dev/
    ProxyPassReverse / http://192.168.144.100:80/example.com/dev/
</VirtualHost>

Solution 2:

look here Using Virtual_host and mod_proxy together for an example

<VirtualHost *:80>
    ProxyPreserveHost On
    ServerName dev.example.com
    ProxyPass / http://192.168.144.100:80/
    ProxyPassReverse / http://192.168.144.100:80/
</VirtualHost>

<VirtualHost *:80>
    ProxyPreserveHost On
    ServerName sandbox.example.com
    ProxyPass / http://192.168.144.100:80/
    ProxyPassReverse / http://192.168.144.100:80/
</VirtualHost>

When enabled, this option ([ProxyPreserveHost][1]) will pass the Host: line from the incoming request to the proxied host, instead of the hostname specified in the ProxyPass line.


I think (but not sure) that, in this case, you can even do it without ProxyPreserveHost, like so:

put this in your frontend hosts file

192.168.144.100 dev.example.com
192.168.144.100 sandbox.example.com

then do this:

<VirtualHost *:80>
    ServerName dev.example.com
    ProxyPass / http://dev.example.com/
    ProxyPassReverse / http://dev.example.com/
</VirtualHost>

<VirtualHost *:80>
    ServerName sandbox.example.com
    ProxyPass / http://sandbox.example.com/
    ProxyPassReverse / http://sandbox.example.com/
</VirtualHost>