Debian/Ubuntu & Apache 2: Transparent reverse proxy with mod_proxy


Here is a tutorial how to use the apache module mod_proxy to set up a transparent reverse proxy that passes all requests to another web server.

Under Debian or Ubuntu you have to enable the modules proxy and proxy_http:

# sudo a2enmod proxy
# sudo a2enmod proxy_http

A use case for a transparent proxy is to route all requests to a public domain (your-public-domain.com in the example) to a private (hidden) domain (your-private-domain.com in the example), e.g. to hide the complexity of your domain/server structures. The virtual host configuration looks as follows:



        ServerName your-public-domain.com

        
                Order deny,allow
                Allow from all
        

        ProxyPass / http://your-private-domain.com/
        ProxyPassReverse / http://your-private-domain.com/


After restarting the apache the proxy modules and your host configuration should be active:

# /etc/init.d/apache2 restart

If you find the following error message in your web server’s error log file (/var/log/apache2/error.log)

[warn] proxy: No protocol handler was valid for the URL /. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.

you do not have to enable the module proxy_http (see above).


5 responses to “Debian/Ubuntu & Apache 2: Transparent reverse proxy with mod_proxy”

  1. Thank you for the quick and simple outline of doing this in Debian. I did find a typo… to restart Apache on my machine at least it is
    sudo /etc/init.d/apache2 restart

  2. Hi Jan.
    I do as your instruction but it not works for me.
    I have a public domain name mydomain.com point to a static ip from my ISP. I config the modem to point all request from port 80 to a local machine 192.168.1.100 through NAT.

    Now i want to have 2 sub domain to point to 2 different IP:
    sub1.mydomain.com –> 192.168.1.101
    sub2.mydomain.com –> 192.168.1.102

    So i try to use proxy module of apache2 in 192.168.1.100 but not succeed.
    Do i think right? Can you please help me?

Leave a Reply

Your email address will not be published. Required fields are marked *