Apache Proxy Pass on Ubuntu

The Apache module mod_proxy can be used to 'reverse proxy' requests through an Apache server to another server. This is most useful when proxying requests to a server behind a firewall which is not directly accessible from the internet. In this example there are 2 servers internalserver.com and externalserver.com There is an application running at the root of internalserver.com which we would like to make available externally at the address: http://externalserver.com/internalapp

  1. Enable mod_proxy with
    a2enmod proxy

    This will place a symbolic link from

    /etc/apache2/mods-enabled/proxy.conf -> /etc/apache2/mods-available/proxy.conf

  2. Inside a Virtual Host definition add (ProxyRequests should be off – on is a security risk without further controls):
    1
    <br />
    1
       ProxyRequests Off

    1
       ProxyPass        /internalapp  <a href="http://internalserver.com/" title="http://internalserver.com">http://internalserver.com</a>

    1
       ProxyPassReverse /internalapp  <a href="http://internalserver.com/" title="http://internalserver.com">http://internalserver.com</a>

    1
     
  3. Edit /etc/apache2/mods-enabled/proxy.conf
    <Proxy *>
    Order deny,allow
    Deny from all
    #Allow from .your_domain.com
    </Proxy>
    The Deny from all line needs changed to allow the reverse proxy to work.
  4. Reload Apache
    /etc/init.d/apache2 reload

  5. Test the internal application on the external server at: http://externalserver.com/internalapp

Post comment