Apache proxy virtual host on backend server

apache-2.2PROXYvirtualhost

I have 2 web Debian servers, a frontend accepting request from port 80 and a backend via proxy from the frontend.

What I want to do is have a many different URLs going the backend server with virtual hosts.

Here is the frontend Apache setting

<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/
    ProxyPassReverse / http://192.168.144.100:80/
</VirtualHost>

And here is the backend Apache setting

 <VirtualHost *:80>
                ServerAdmin webmaster@localhost

                DocumentRoot /var/www/
                <Directory />
                        Options FollowSymLinks
                        AllowOverride None
                </Directory>
                <Directory /var/www/>
                        Options Indexes FollowSymLinks MultiViews
                        AllowOverride None
                        Order allow,deny
                        allow from all
                </Directory>
    </VirtualHost>
    <VirtualHost *:80>
            ServerAdmin webmaster@localhost

            ServerName dev.example.com

            DocumentRoot /var/www/example.com/dev/
            <Directory />
                    Options FollowSymLinks
                    AllowOverride None
            </Directory>
            <Directory /var/www/example.com/dev/>
                    Options Indexes FollowSymLinks MultiViews
                    AllowOverride None
                    Order allow,deny
                    allow from all
            </Directory>
    </VirtualHost>

   <VirtualHost *:80>
            ServerAdmin webmaster@localhost

            ServerName sandbox.example.com

            DocumentRoot /var/www/example.com/sandbox/
            <Directory />
                    Options FollowSymLinks
                    AllowOverride None
            </Directory>
            <Directory /var/www/example.com/sandbox/>
                    Options Indexes FollowSymLinks MultiViews
                    AllowOverride None
                    Order allow,deny
                    allow from all
            </Directory>
    </VirtualHost>

When I go to dev.example.com or sandbox.example.com, it takes me to the default /var/www files.

Basically, I want the ability to run multiple virtual hosts on the backend server.

Thanks for your help.

Best Answer

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>
Related Topic