How to Setup a Reverse Proxy with Apache Mod_Proxy?

August 19, 2014 / Apache Web server

Today, we will see the implementation of Apache as a reverse proxy in the front end of another apache server that will be its back end. We use this module Mod_Proxy and Mod_Proxy_HTTP.

We just try to redirect the flow arriving at a destination server of a domain name to a server located further upstream in the architecture.

We do not discuss here the subjects of Load distribution. Or load balancing that can perform the role of a reverse proxy. The system of reverse proxy may here be summarized as follows:

Therefore, there is a first server front-end that receives all requests. And multiple web servers’ backend that each contains a different website (or even as part of a load balancing).

So we will set up the reverse proxy server to redirect requests according to each URL and the requested content.

This done by folder (for example, just redirect / image to a specific server) or a full URL, what we see here:


To illustrate the implementation of our Apache reverse proxy, here we will follow the below schedule:

So we have a first server with the public IP that will receive all requests from clients. It contains the, then a second server which contains the website

So we will configure our first server Reverse Proxy. So that it redirects requests to by the second server, fulfilling its role as a reverse proxy.

However, it will continue to respond to those requests for, to illustrate how a normal website uses a reverse proxy:

We assumed here that the machines are in place at the OS level, network, and have a functional Apache server with a website on each machine that meets the good URL.

Installation and Configuration

We will initially activate proxy_http on the reverse proxy server. This is the module mod_proxy specific to the HTTP protocol that we work with here. For this, we entered the below command:

| a2enmod proxy_http

1) The module “proxy” should be activated at the same time:
2) We will then restart apache2 so that the modules are active:

| Service apache2 restart

We will now create two virtual hosts. One will lead requests to local content and another who has the role of the reverse proxy and direct the requests to the second server with a standard configuration.

| touch /etc/apache2/sites-available/
| touch /etc/apache2/sites-available/

We will not perform these configurations: here we willingly place only the information that is needed to keep the bulk seen in:

Here is the configuration

< VirtualHost *:80 >
	DocumentRoot /var/www/firstdomain
< /VirtualHost > 

Here is the configuration of which is the one that will be the reverse proxy:

< VirtualHost *:80 >
	ProxyPreserveHost On
	ProxyRequests On
	ProxyPass /
	ProxyPassReverse /
< /VirtualHost >

Then we can enable them:

| a2ensite
| a2ensite

We can now reload the configuration of Apache2

| Service apache2 reload

We will now proceed to the test.

Note: At this point, we also verify that the test website (here and be resolved with DNS level to bring the worm first server with the role of a reverse proxy.

For this you just have to go on both websites, the largest being of course to have a response from the second server that is located behind the reverse proxy:

We have a reverse proxy server in place.

Go further

To go further, it is common to find this kind of advanced server with security features or cache. One can for example use the Apache module to reduce server load.

There is also the module mod_security which filters requests and blocks some of them if they appear to undermine the security of websites.

In addition, the reverse proxy is often used for functions of load sharing and load balancing which likely to see in another tutorial.

Incoming searches related to apache reverse proxy

  1. apache reverse proxy example
  2. apache reverse proxy Ubuntu
  3. apache2 reverse proxy
  4. apache reverse proxy virtual host
  5. apache reverse proxy rewrite
  6. apache reverse proxy ssl
  7. apache reverse proxy authentication
  8. apache reverse proxy is
Read Also: How to Use WHM to Download a Domain’s Raw Apache Logs