Apache Reverse Proxy

In my last article i told you about the Apache proxy server and its types. Now today i am going to show you how to configure reverse proxy on your Apache server. Now after reading the Apache proxy article, you already know what is Apache proxy and its type reverse proxy. So without wasting much time here i am going to present you the scenario and its solutions.
So lets start now.

Scenario:

IT Manger of your company has given you a task. Your company has their own commercial Website which includes Accessories, Cosmetic products, Food coupons, Gadgets, Foot wears, Entertainment and Adventure and many other items for sale. Now one of your company’s client wants to include one of your comany product page to their website. Lets me briefly clear here:

  • Clients websites is ‘www.abc.com’
  • Your Company website is ‘www.xyz.com’
  • At the URL ‘www.xyz.com/cosmetic’, you have cosmetic product for sale.
  • Client wants to include ‘www.xyz.com/cosmetic’ in his website which is ‘www.abc.com/cosmetic’.

As client was not technically very strong, he had just purchased a domain name and hosting. Now he wants us to take the access of his VPS and implement all the required setting there. Now if you have understand the requirement, you already know that all you need to do is to configure Reverse Proxy in the Apache web server of client.

 

 

 

 

 

 

 

 

Have a look at the configuration file ‘httpd.conf’ of clients apache web server before implementing the Reverse proxy.

 [root@Client ~]# vim /etc/httpd/conf/httpd.conf
 

 <VirtualHost *:80>
ServerAdmin  client@abc.com
DocumentRoot /var/www/public_html
ServerName www.abc.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost> 

This is how VirtualHost of ‘www.abc.com’ looks like. But before making any changes in apache virtualhost, make sure that you have installed apache reverse proxy moudles which i have already mentioned in my last post. Though these modules are always pre-installed but in case if you have installed apache with soruce code and have fogotten to enable apache proxy module,you don’t need to worry as you can still enable these modules. Here is the list of modules that needs to be compulsory installed:

mod_proxy: Core module which manges the configuration and proxy requests
mod_proxy_http: Fetches document with HTTP and HTTPS.
mod_proxy_ftp: Fetches document with FTP
mod_proxy_connect: Used to tunnel SSL requests through proxy server
mod_proxy_ajp: Provides support for the JServ protocol
mod_proxy_balancer: mod_proxy extension for load balancing
mod_cache, mod_disk_cache, mod_mem_cache: Manges document cache
mod_proxy_html: Rewrites HTML links into a proxy’s address space
mod_headers: Modifies HTTP request and response headers
mod_deflate: Negotiates compression with clients and backends

So now if you have installed these modules, you can proceed further. Now let see what directives you need to put in VirtualHost.

 <VirtualHost *:80>
ServerAdmin client@abc.com
DocumentRoot /var/www/public_html
ServerName www.abc.com
ProxyRequests Off
ProxyPassReverseCookiePath / /
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://www.xyz.com/cosmetic/
ProxyPassReverse / http://www.xyz.com/cosmetic/
</VirtualHost>
 

ProxyRequests: This directive enable your server as a apache proxy. If you are going to make it as a Forward proxy, you will set its mode ‘on’, but as we are going to configure it as reverse proxy,we do not need to make it ‘on’. We set it as ‘off’ as we are going to configure apache as a reverse proxy.

ProxyPassReverseCookiePath:- This directive retains the original path of url in cookies. If you want to store the session, you can use it but if you don’t want to just leave it.

ProxyPass: This directive allows remote servers to be mapped into the space of the local server.

ProxyPassReverse: ProxyPass directive doesn’t perform “clean” reverse proxying. In ProxyPass directive,the HTTP headers of packets doesn’t change. It means, if you are browsing a reverse proxy url from browser using ProxyPass directive only, the client browser will be able to know the actual source of the data which is strictly a big NO.

Now just one more thing is required which is restarting the ‘httpd’ daemon.

 [root@Client ~]# service httpd restart
 

Thats it. You have successfully configured your apache server as a reverse proxy.

Congrats…!!!

 

 

 

Both comments and pings are currently closed.

Comments are closed.