Home » Linux » Learn More » Apache Reverse Proxy & Forward Proxy

Apache Reverse Proxy & Forward Proxy

What is Apache Forward Proxy ?

Forward proxies act as a gatekeeper between client browsers on your local network and internet accessed by those clients. The forward proxy will receive the HTTP requests, perform any filtering or request alteration rules you establish, and when appropriate, forward the request to destination. The response will return through your proxy, where it may optionally be cached and/or modified, and then returned to the original client.  Users or clients must configure their browsers or operating system to use a proxy server (Apache Forward Proxy) to be able to access the internet.

apache-proxy-01

What is Apache Reverse Proxy ?

Reverse Apache is different mechanism, its act like a firewall,  Apache Reverse Proxy enable network outsider client or user to access applications inside the Apache server machine, the application may be some other web server like Nginx or another Apache.

apache-proxy-02

Experiment Environment

OS : CentOS 6 x64
IP : 10.0.10.4

Setup Apache Forward Proxy

1. Install Necessary Software

[root@unixhops ~]# yum install httpd mod_ssl

2. Configure forward apache proxy setup

Add a proxy configuration file to default apache configuration directory

[root@unixhops ~]# nano /etc/httpd/conf.d/frd-proxy.conf

Put this code into the file

 ProxyRequests On
 ProxyVia On
 ProxyTimeout 60
 <Proxy *>
 Require local
 Require ip 10.0.10.4/255.0.0.0
 </Proxy>

The “ProxyRequests” parameter and “ProxyVia” is needed to enable proxy on Apache.

here are many more parameters available – this is just basic configuration – read more about additional parameters HERE.

3. Change Default Apache Port

You need to change default listen port

[root@unixhops ~]# nano -w /etc/httpd/conf/httpd.conf

Find line “Listen 80” & change to “Listen 8080”

4. Setup Your Browser

firefox-apache-forward-proxy

Setup Reverse Apache Proxy

1. Install Necessary Software

[root@unixhops ~]# yum install httpd mod_ssl

2. Configure forward apache proxy setup

Add a proxy configuration file to default apache configuration directory

[root@unixhops ~]# nano /etc/httpd/conf.d/rev-proxy.conf

Put this code into the file

 ProxyRequests Off
 ProxyPass /dir http://10.0.10.4:8080/dir
 ProxyPassReverse /dir http://10.0.10.4:8080/dir

ProxyPass parameter pass all request with /dir to machine IP 10.0.10.4, port 8080. Parameter ProxyPassReverse work as vice verse mode.

3. Rewrite HTML Links

This is an example of basic apache reverse proxy.

If you setup this type of setup you can get some error when some web application is written with local address. to solve this error you need to install a apache module called mod_proxy_html

 [root@unishops ~]# yum install mod_proxy_html
 [root@unixhops ~]# cp /usr/share/doc/httpd-2.2.4/proxy-html.conf /etc/httpd/conf.d/

Finally you need to restart apache

[root@unixhops ~]# service httpd restart

Check Also

Apache MPMs Explanation

MPM or multiprocessing modules are part of the apache code that handle incoming requests. So …

3 comments

  1. Hi,

    Thank you for the info. Its very useful.

    Can you please tell is it possible to configure same apache server to act as both forward and reverse proxy?
    Can you please share the configuration if you have any?

    Thanks.

  2. Hi,

    Many thanks, simple but really helpful

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: