Reverse Proxy on Apache2

Wednesday, October 27, 2010
What is reverse proxy?
According to Apachetutor reverse proxy is a gateway for servers, and enables one web server to provide content from another transparently


In what scenario it can be use?
Company example.com has a website at www.example.com, which has a public IP address and DNS entry, and can be accessed from anywhere on the Internet.

The company also has a couple of application servers which have private IP addresses and unregistered DNS entries, and are inside the firewall. The application servers are visible within the network - including the webserver, as "internal1.example.com" and "internal2.example.com", But because they have no public DNS entries, anyone looking at internal1.example.com from outside the company network will get a "no such host" error.

A decision is taken to enable Web access to the application servers. But they should not be exposed to the Internet directly, instead they should be integrated with the webserver, so that http://www.example.com/app1/any-path-here is mapped internally to http://internal1.example.com/any-path-here and http://www.example.com/app2/other-path-here is mapped internally to http://internal2.example.com/other-path-here. This is a typical reverse-proxy situation.

How do i enable Apache2 for proxy?
To enable Apache2 for proxy, you need to enable this modules :

  • mod_proxy: The core module deals with proxy infrastructure and configuration and managing a proxy request.
  • mod_proxy_http: This handles fetching documents with HTTP and HTTPS.
  • mod_proxy_ftp: This handles fetching documents with FTP.
  • mod_proxy_connect: This handles the CONNECT method for secure (SSL) tunneling.
  • mod_proxy_ajp: This handles the AJP protocol for Tomcat and similar backend servers.
  • mod_proxy_balancer implements clustering and load-balancing over multiple backends.
  • mod_cache, mod_disk_cache, mod_mem_cache: These deal with managing a document cache. To enable caching requires mod_cache and one or both of disk_cache and mem_cache.
  • mod_proxy_html: This rewrites HTML links into a proxy's address space.
  • mod_xml2enc: This supports internationalisation (i18n) on behalf of mod_proxy_html and other markup-filtering modules. space.
  • mod_headers: This modifies HTTP request and response headers.
  • mod_deflate: Negotiates compression with clients and backends.
After enabling those modules, we need to edit httpd.conf and insert line like these (do not forget to create the folder you specified below!!!) :

ProxyPass /news/ http://news_server.domain.lan/news/
ProxyPassReverse /news/ http://news_server.domain.lan/news/


And the final step is to edit our mods-enabled/proxy.conf :

ProxyRequest Off

Order deny,allow
Allow from all

ProxyVia On


Read More...