Apache's reverse proxy is an act of an Apache webserver providing content from other webserver transparently. This is useful in many instances such as caching and mirroring, but it's mostly used to serve websites that are hosted behind NAT or a firewall. A reverse proxy server routes connection addressed to the internal server, and the client sees the reverse proxy server itself as the origin server.

For example, Apache can be configured to serve URL's such as http://www.example.com/webapp to actually get the content from, which is hosted from an internal network. This happens transparently and the user initially requesting http://www.example.com/webapp need not to be aware of what happens in the background.

1) Enable proxy modules

Apache require 2 modules enabled for this reverse proxy to work. These modules are proxy and proxy_http. To enable them, run the following command at the terminal.

$ sudo a2enmod proxy_http
Considering dependency proxy for proxy_http:
Enabling module proxy.
Enabling module proxy_http.

That will enable both proxy and proxy_http, as proxy module is actually a dependency to the proxy_http module. This is confirmed by the output of the above command.

Once the module is enabled, you can start configuring the reverse proxy settings.

2) Configure reverse proxy

From the previous example, we would like our public facing webserver at http://www.example.com to host our internal site of to be available as http://www.example.com/webapp

You'll need to add the following lines to your Apache's configuration file.

For Ubuntu, the file could be /etc/apache2/sites-enabled/000-default

ProxyRequests Off
ProxyPass /webapp
ProxyPassReverse /webapp

3) Restart Apache

Apache will have to be restarted for the changes to work.

Guide compatibility:

Operating System
Ubuntu 16.04 LTS (Xenial Xerus)
Ubuntu 16.10 (Yakkety Yak)
Ubuntu 17.04 (Zesty Zapus)
Ubuntu 17.10 (Artful Aardvark)
Ubuntu 18.04 LTS (Bionic Beaver)
Ubuntu 18.10 (Cosmic Cuttlefish)
Ubuntu 19.04 (Disco Dingo)
Discuss the article:

Share your thoughts, suggest corrections or just say Hi. Login not required.