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
- 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
- Inside a Virtual Host definition add (ProxyRequests should be off – on is a security risk without further controls):
ProxyRequests Off
ProxyPass /internalapp http://internalserver.com
ProxyPassReverse /internalapp http://internalserver.com
- 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. - Reload Apache
/etc/init.d/apache2 reload
- Test the internal application on the external server at: http://externalserver.com/internalapp