PROXY IN APACHE HTTP SERVER

Hi all, from this post I’m going to talk about proxy in Apache HTTP server. When talking about the proxies, there are two main types of proxies to talk about.

  1. Forward Proxy
  2. Reverse Proxy

FORWARD PROXY

In forward proxy, proxy resides on the client side. Client knows about the server. But client request has to go through the proxy. Proxy will redirect the request to the server. This is useful in situations where we want to block some sites, also we can use the proxy for cache purposes as well. It will reduce the response  time and the bandwidth as well.

forward_proxy-3

After getting the idea about the forward proxy concept, let’s see how to configure the forward proxy on Apache HTTP server.

  • Then go to the Apache installation directory.

1

  • Open the httpd.conf file at conf directory.

2

  • Also open the proxy-html.conf file at extra directory.

3

  • Under the httpd.conf file, we have to uncomment these lines first.

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

  • Then add this line to the file.

Include conf/extra/proxy-html.conf

  • Now go to the proxy-html.conf file and do as following.
  • Add these line to the file.

ProxyRequests On
ProxyVia On
<Proxy “*”>
Require host http://www.google.com/
Order deny,allow
Deny from all
Allow from 172.16.1.125
</Proxy>

  • Now we are good to go.

REVERSE PROXY

Now let’s see the reverse proxy. Here the proxy resides on the server side. All client requests will come to the proxy directly. Client’s have no idea about the server. They request everything from the proxy. Proxy then redirect these requests to the server.

reverse_proxy-resized-600.png

After getting the idea about the reverse proxy concept, let’s see how to configure the reverse proxy on Apache HTTP server.

  • We need the same two files as we used earlier.
  • Uncomment following lines from the httpd.conf file.

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_http_module modules/mod_proxy_http.so

Include conf/extra/proxy-html.conf

  • Then add these lines to the proxy-html.conf file.

ProxyRequests Off
ProxyPass /m/ http://www.google.com/
ProxyHTMLURLMap http://www.google.com/ /m
<Location /m/>
ProxyPassReverse /
ProxyHTMLEnable On
ProxyHTMLURLMap / /m/
RequestHeader    unset  Accept-Encoding
</Location>

  • Now we can access the google.com through the proxy like below.

http://localhost/m/

LOAD BALANCER

This is another important topic to talk about. Let’s get an idea about the load balancer. When thousand’s of requests come to a server, some times it will crash. Won’t be able to serve the client requests. Response time can be increased dramatically. Because of these reasons we can use a load balancer. Load balancer works with the reverse proxy technique. It will take client requests from the proxy and then redirect them to different servers. There are few algorithms in used to find the server to which the request should go.

load-balancing-1.png

After getting the idea about the load balancer concept, let’s see how to configure the load balancer on Apache HTTP server.

  • We can use the same two files we used in previous occasions.
  • Uncomment following lines from the httpd.conf file.

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

Include conf/extra/proxy-html.conf

LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule lbmethod_byrequests_modulmodules/mod_lbmethod_byrequests.so

  • Here I’m using the byrequests algorithm. There are few other techniques as well,
    1. byrequests
    2. bytraffic
    3. bybusyness
  • According to the algorithm we are using, we have to uncomment the suitable module in the httpd.conf file.
  • Now add these lines to the proxy-html.conf file.

ProxyRequests Off
<Proxy balancer://myset>
BalancerMember http://localhost:8080/ussd-mgmt-ui/
BalancerMember http://localhost:8081/ussd-mgmt-ui/
ProxySet lbmethod=byrequests
</Proxy>

<Location /balancer-manager>
SetHandler balancer-manager
Require host localhost
</Location>

ProxyPass /m/  balancer://myset/
ProxyPassReverse /m/  balancer://myset/

  • Here I’m using my own application at two different ports as two servers. You have to change the lbmethod according to the algorithm you are using.

Hope now you have a clear idea about the proxy in Apache HTTP server. See you soon with another interesting topic. Thank You!

Advertisements

One thought on “PROXY IN APACHE HTTP SERVER

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s