How to install mod_proxy and setup reverse proxy in Apache Ubuntu
Today in this tutorial we will learn about installing apache proxy module and how to setup reverse proxy.
The module name is mod_proxy ,it is core module which supports Forward and Reverse Proxy settings in Apache WebServer. There are other modules also which is required in Apache webserver as per the requirement for example
mod_proxy_http, mod_proxy_ftp, mod_proxy_ajp, mod_proxy_balancer, and mod_proxy_connect
Reverse proxy is widely used to access the webserver which is behind the firewall.Reverse Proxy has the capability to load balance the request among the backend-server as well caching can also be done.Mainly, reverse proxies can be used simply to bring several servers into the same URL space.
For eg. lets see this scenario –
We have One Web server which has public ip address and DNS record means it can be accessible by using the url www.example.com or http://example.com
We have some internal webserver lets assume, internalwebserver1,internalwebserver2 and internalwebserver3. Internal web servers can not be access directly from public internet because they have private IP as well as they are behind the firewall. Means if someone try to access these internal server it will get error No such host.
But there are some important web application or webpages are serving from internal web server which is required to map with example.com .
So in this case what we will do we will setup the Reverse Proxy server. If any request come to main URL i.e example.com the Web Server will check which path is mapped to its internal web server in configuration file.
OK have this another Scenarios –
I have one OpenERP server which runs in port no. 8069 eg. http://openrp.example.com:8069 but I would like to open the website openerp.example.com in URL means port no. 80 bydefault. In this case also we can setup reverse proxy in single openerp server.
Install mod_proxy and setup reverse proxy in Apache Webserver
Follow the given below steps.
Note: In all given below example replace the value of ServerAdmin,ServerName & ServerAlias as per your server information
Step 1: Install the module
sudo apt-get install libapache2-mod-proxy-html
Step 2: Installing the dependency libxml2-dev
apt-get install libxml2-dev
Step 3: Load the module
a2enmod proxy proxy_http
Step 4: Create the Virtual Host in apache configuration file . If your configuration is located in conf.d you have to do changes in that file. I am giving example with default setting in Apache Webserver in Ubuntu
Paste the below two lines within VirtualHost tag
ProxyPass /foo http://internalwebserver1.example.com/give/path/of-requested-location ProxyPassReverse /foo http://internalwebserver1.example.com/give/path/of-requested-location
Lets see the configuration of my file,it will clear the doubt
<VirtualHost *:80> ServerAdmin [email protected] ServerName example.com ServerAlias example.com ProxyPass /foo http://internalwebserver1.example.com/files/webapp ProxyPassReverse /foo http://internalwebserver1.example.com/files/webapp </VirtualHost>
Step 5: Now restart the apache
Step 6: Now Openbrowser in client machine and check the website. Done
Now for Scenario 2:
Follow the all above given steps except in Step 4 you have to do below given setting
Below is the reference of my configuration file
<VirtualHost *:80> ServerAdmin [email protected] ServerName openerp.example.com ServerAlias openerp.example.com ProxyPass / http://openerp.example.com:8069 ProxyPassReverse / http://openerp.example.com:8069 </VirtualHost>
Restart the apache2 and open the browser and check it