Technology weblog

IT-Essence
Friday Dec 22, 2006

Reverse proxy with Apache

Suppose we have a service running on a server, which is known as server.mydomain.com to the outside world. To the intranet, this server may be available under a different name (as a matter of fact, in my configuration at home it actually does), but for the moment let's assume that the URL of the service running on the local serer is available at:

http://localhost:9090/service/url

and we want to make it available on the Internet via

http://server.mydomain.com/service/url

First of all, Apache must be configured to act as a reverse proxy. To this extent, locate your httpd.conf (on Gentoo Linux, this config file resides in the /etc/apache2 directory). Make sure  mod proxy is enabled by asserting that the following line has been uncommented:

LoadModule proxy_module    modules/mod_proxy.so
Add the following snippet to your httpd.conf and modify it according to your own specific service settings
<IfModule mod_proxy.c>
ProxyRequests Off
ProxyPass /service http://127.0.0.1:9090/service
ProxyHTMLURLMap http://127.0.0.1:9090/ http://server.mydomain.com/
<IfModule>
Finally, you'll most probably need URL rewriting too, as URLs in your HTML documents need to be converted as well. To this extent, navigate to your modules.d direcotry (in my case in the /etc/apache2/ dir) and look for a file xy_mod_proxy_html.conf, where in my case xy equals 27. Make sure it is enabled by asserting that the following two lines are present and uncommented:
LoadFile    /usr/lib/libxml2.so
LoadModule proxy_html_module    modules/mod_proxy_html.so
Add the following snippet, modified for your local set-up as needed
<IfModule mod_proxy_html.c>
ProxyHTMLLogVerbose On
SetOutputFilter proxy-html
ProxyHTMLURLMap / http://server.mydomain.com/
<IfModule>
That should be all that's needed. If you have any remarks, please leave a comment!

Comments:

Post a Comment:
Comments are closed for this entry.

Hire us
Archives
Tags
Links
Stats
Referrers