Results 1 to 2 of 2

Thread: How TO: Two Web Servers, One IP address = reverse Proxy

  1. #1
    Join Date
    May 2007
    Location
    NY's first capital
    Beans
    2,868
    Distro
    Ubuntu 20.04 Focal Fossa

    How TO: Two Web Servers, One IP address = reverse Proxy

    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
    1. 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.
    2. This assumes you have NameVirtualHosts already working on both servers.
    3. Enable proxy on your main server.
    4. Create a vhost (on main server) for you site that is hosted elsewhere.
    5. 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.
    Nothing is ever easy, but if it is difficult you must be doing it wrong.

  2. #2
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: How TO: Two Web Servers, One IP address = reverse Proxy

    Just a note to remind people we're talking about HTTP only here. HTTPS requests don't easily lend themselves to being proxied. It's possible but not for the faint-of-heart. Usually the easiest solution is to forward traffic for port 443 to that port on the internal server. You can use iptables for this task, or an application-level proxy like this one.
    Last edited by SeijiSensei; February 5th, 2012 at 07:49 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •