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:

Architecture

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 10.10.10.21 that will receive all requests from clients. It contains the www.firstdomain.com, then a second server which contains the website www.seconddomain.com.

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

However, it will continue to respond to those requests for www.firstdomain.com, 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 www.firstdomain.com requests to local content and another who has the role of the reverse proxy and direct the requests to the second server www.secondserver.com with a standard configuration.

| touch /etc/apache2/sites-available/firstdomain.com
| touch /etc/apache2/sites-available/seconddomain.com

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 firstdomain.com

< VirtualHost *:80 >
	ServerName www.firstdomain.com
	DocumentRoot /var/www/firstdomain
< /VirtualHost > 

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

< VirtualHost *:80 >
	ServerName www.seconddomain.com
	ProxyPreserveHost On
	ProxyRequests On
	ProxyPass / http://10.10.10.23/
	ProxyPassReverse / http://10.10.10.23
< /VirtualHost >

Then we can enable them:

| a2ensite firstdomain.com
| a2ensite seconddomain.com

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 firstdomain.com and seconddomain.com) 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