7

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.

tdbui22
  • 103
  • 1
  • 2
  • 6
  • If I understand You well - just add all domains you want to support in your frontend server (a.example.org, b.example.org, c.example.org etc etc) and then on backend, you should receive specific domain (a, b, c etc.) and make it point to specific Documentroot. Is that what you want to achieve ? – wojciechz Jan 29 '13 at 01:27
  • That's exactly what I want to do and I did just that above. In the frontend I have dev.example.com and sandbox.example.com proxying to the same IP http://192.168.144.100:80/. On the backend I have a virtual host setup for dev.example.com and sandbox.example.com with their own documentroot. But going to dev or sandbox always takes me to the default virtualhost. – tdbui22 Jan 29 '13 at 01:37

2 Answers2

7

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>
  • 1
    Small correction on the directories but I get your point. Worked perfectly. Thank you. – tdbui22 Jan 29 '13 at 03:04
  • Hi, I tried with below configuration but somehow its not wokring. Please let me know if am I doing somethig wrong. `ProxyPass /dashboard http://dashboard.example.com/` – Anil Kumar Pandey Oct 29 '16 at 09:14
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>
Athmailer
  • 21
  • 2