15 February 2012

67. Neat trick using reverse proxy -- several http hosts behind a firewall with only one port open

The situation: I was running two wireless webcams (Airlink101 AIC 250W) in order to monitor my laboratory. Both of these were connected to a linksys router. Only port 22 and 80 were opened by the university. We were forwarding port 80 to a Debian box running apache.

The goal: We wanted to have a page, e.g.www.externalhostname.com/image.html, serve up images from both the webcams. Using apache.

The solution:
A friend came up with this neat solution.

The following is assumed:
  • The external dns name is www.externalhostname.com
  • The cameras have the LAN ips and

First the html file -- image.html:

<title>Lab Webcams</title>
<body bgcolor="rgb(0,0,122)" text="white">
<table border="1">
Cam 1480
Cam 1485
<img src="http://www.externalhostname.com/cam1/image.jpg" width="320" height="240"/>
<img src="http://www.externalhostname.com/cam2/image.jpg" width="320" height="240"/>
Next, configure apache using /etc/apache2/httpd.conf:
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
LoadModule proxy_connect_module /usr/lib/apache2/modules/mod_proxy_connect.so
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
ProxyPass /cam1
ProxyPassReverse /cam1
ProxyPass /cam2
ProxyPassReverse /cam2

Finally, copy the following from /etc/apache2/mods-available to /etc/apache2/mods-enabled:
<IfModule mod_proxy.c>

# Depends: proxy
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so

LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so

That's it.

No comments:

Post a Comment