I have seen this request several times. I have also wanted to get this working myself.
Scenario, you have multiple Web Servers, either Physical or VM's, each with their own ip inside your LAN/firewall.
This can be two Linux servers, or Linux and Windows IIS, or any combination really.
Question: How can you have more than one machine serve websites on port 80 with only one IP address from your isp?
Answer: Use Reverse Proxy.
This can be done using Apache2, Nginx or you favorite HTTP server. I have chosen Apache2, but others may opt for Nginx when a light weight server is desired.
QuickList
- Decide which machine will be the "Main" Server. This will be the server that has port 80 forwarded from your router. This will be your proxy server machine.
- This assumes you have NameVirtualHosts already working on both servers.
- Enable proxy on your main server.
- Create a vhost (on main server) for you site that is hosted elsewhere.
- Reload apache and test.
Main server
Code:
sudo a2enmod proxy_http
Code:
sudo a2enmod rewrite
Code:
nano /etc/apache2/sites-available/site_hosted_elswhere
Code:
#This is for virtual host sites on server2 @ 192.168.1.3
<VirtualHost *>
ServerAdmin webmaster@domain.com
ServerName elswhere.domain.com
# You can have list of space separated aliases if you server2 hosts multiple domains
ServerAlias elswhere2.domain.com elswhere.domain.com otherdomain.net
# If you have multiple hosts (NameVirtualHosts on server 2, you will need to preserve
# hostname, or you will always land at the root of
# the second server… ie: what ever the default site is.
ProxyPreserveHost on
# Need to allow location / if you want the proxy to
# work when no folder is written in the url.
<location />
allow from all
</location>
# This is where all the magic happens.
# You can modify the following for specific folders only and any remote host
# you can also specify a different port if you like
ProxyPass / http://192.168.1.3/
ProxyPassReverse / http://192.168.1.3/
</VirtualHost>
Code:
sudo service apache2 restart
You should have a working setup. Make sure to clear browser cache before testing.
Bookmarks