How to Configure Apache2 as Forward and Reverse Proxy

This is a cook recipe to configure an Apache2 as a forward and reverse proxy on Debian-based Linux systems like Ubuntu or Debian itself.


It is assumed that the apache2 package is already installed on your system. For the proxy feature, we have to install the Apache2 module libapache2-mod-proxy-html on the system and activate theses Apache modules. At the end, Apache2 has to be restarted, so that the modules can be used.

1sudo apt-get install libapache2-mod-proxy-html
2sudo a2enmod proxy
3sudo a2enmod proxy_html
4sudo a2enmod proxy_http
5sudo service apache2 restart

Configuration Forwarding and Rewarding

We want to forward the URL request to and rewarding to for every response. For that, we have to create a so-called Virtual Host in Apache2. It is easiest to copy the configuration of the default one and adjust it.

1cd /etc/apache2/sites-available
2sudo cp 000-default.conf jenkins_ci.conf

It is best practice to create one conf file per Virtual Host. Adding and removing Virtual Host is easier with this approach.

The content of the Virtual Host configuration should look similar to the following one:

 2  ServerName
 4  ServerAdmin webmaster@localhost
 6  ProxyRequests Off
 7  <Proxy *>
 8    Order deny,allow
 9    Allow from all
10  </Proxy>
11  ProxyPass / http://localhost:8083/
12  ProxyPassReverse / http://localhost:8083/
14  ErrorLog ${APACHE_LOG_DIR}/error.log
15  CustomLog ${APACHE_LOG_DIR}/access.log combined

We have to add the host name (in this case to the line 1 and 2, so that Apache2 knows for which host name is this Virtual Host. In line 11 and 12 the mapping is configured (in this case, everything that call the host name directly should be forwarded to http://localhost:8083; the opposite for rewarding). At the end this configuration has to be enabled.

1sudo a2ensite jenksin_ci.conf
2sudo service apache2 reload


Further Information