Subscribe to RSS Feed

Reverse Proxy Server

December 7, 2009 by admin

Reverse Proxy Server

 

Written by: Frank Mancuso

Website: http://frankmancuso

In this document, I will show you how to use Apache 2 to server as a front end to different internal web server. You will be able to serve over one internet IP address a bunch of back bone web servers.

Compiling Apache2

http://httpd.apache.org/ ( download the latest version of Apache 2 )

In this document, I will use version 2.0.59.

mkdir /usr/local/www

mkdir /usr/local/www/src

cd /usr/local/www/src

wget http://apache.oregonstate.edu/httpd/httpd-2.0.59.tar.gz

tar –xzvf httpd-2.0.59.tar.gz

cd httpd-2.0.59

./configure –prefix=/usr/local/www/proxy \
–with-mpm=worker –enable-suexec –with-suexec-caller=proxy \
–with-suexec-userdir=/usr/local/www/proxy/htdocs \
–enable-rewrite –enable-mime-magic –disable-charset-lite \

–disable-include –disable-status –disable-autoindex \
–disable-cgid –disable-cgi –disable-negotiation –disable-imap \
–disable-userdir –disable-asis –enable-alias –enable-so \
–enable-headers –enable-logio –enable-proxy –enable-proxy-http \
–enable-http
 

make

make install

groupadd proxy
useradd -g proxy -d /dev/null -s /bin/false proxy

 

 

Putting it into action

This is a sample of my httpd.conf file.

## Proxy Server Config

ServerRoot “/usr/local/www/proxy”
Timeout 300
KeepAlive On

MaxKeepAliveRequests 100
KeepAliveTimeout 15
Listen 80

User proxy
Group proxy

ServerAdmin root@localhost

UseCanonicalName Off

DocumentRoot “/usr/local/www/proxy/htdocs”

<Directory />
    Options FollowSymLinks
    AllowOverride None

</Directory>

<Directory “/usr/local/www/proxy/htdocs”>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all

</Directory>

DirectoryIndex index.html

<FilesMatch “^\.ht”>
    Order allow,deny
    Deny from all

</FilesMatch>

TypesConfig conf/mime.types

DefaultType text/plain

<IfModule mod_mime_magic.c>
    MIMEMagicFile conf/magic
</IfModule>

HostnameLookups Off

ErrorLog logs/error_log
LogLevel warn

LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”" combined
LogFormat “%h %l %u %t \”%r\” %>s %b” common

LogFormat “%{Referer}i -> %U” referer
LogFormat “%{User-agent}i” agent

CustomLog logs/access_log common

ServerTokens Prod

ServerSignature Off

 

NameVirtualHost 10.0.0.1 # Note: replace 10.0.0.1 with your external ip address

 

# This first virtual host, I will forward http requests to a server running on the local class #A ip address.

<VirtualHost 10.0.0.1>
   ServerAdmin root@localhost

   ServerName example.local
   ServerAlias  www.example.local

ProxyPass               / http://10.0.0.3/example/
ProxyPassReverse        / http://10.0.0.3/example/

</VirtualHost>

 

# This example, I can use a sub directory on a different host Let says I just wanted to host # a directory on my main web site that was written in ASP or JSP, so I would forward it a # internet web server.

 

<VirtualHost 10.0.0.1>
   ServerAdmin root@localhost

   ServerName example.local
   ServerAlias  www.example.local

ProxyPass               /pdf http://10.0.0.4/pdf/
ProxyPassReverse        /pdf http://10.0.0.4/pdf/

</VirtualHost>

 

# Now when someone visited http://example.local/pdf/ it would be reversed to #10.0.0.4/pdf/

 

 

After playing around in your test lab, you should get an idea how easy Apache 2 can be used as a reverse proxy server.

 

Leave a Reply