# Apache Reverse Proxy

## Cocker68

Hello,

I was trying to configure Apache as a reverse proxy, and I want to share my experiences, for I didn't find anything particular in the Gentoo forums.

Apache was already serving a website, and now I wanted to let appear another webserver from inside the LAN (actually a mobotix webcam) in this Apache's namespace.

I put into /etc/apache2/conf/commonapache2.conf:

```
<IfModule mod_proxy.c>

    ProxyRequests Off

    ProxyPass /webcam/ http://webcam.local/

    ProxyPassReverse /webcam/ http://webcam.local/

</IfModule>
```

This works perfectly, and I can access the webcam from extern.

However the webcam's pages contain URLs with absolute references instead of relative ones (e.g. /admin/ ).  Accessed from extern those URLs will point to nonexistant directories on the Apache-server.

I learned (http://www.apacheweek.com/features/reverseproxies) that in this case URLs in the HTML code have to be rewritten while being proxied (e.g. /admin/  -->  /webcam/admin/ ) by another Apache module called mod_proxy_html, which is not in portage, but can be downloaded as source code from http://apache.webthing.com/mod_proxy_html/

The easyest way to compile mod_proxy_html, is by the command

```
# apxs2 -a -c -I/usr/include/libxml2 -i mod_proxy_html.c
```

This will compile the module as well as it will add a line to apache2.conf:

```
LoadModule proxy_html_module  lib/apache2/modules/mod_proxy_html.so
```

Upon restart Apache will complain

```
Cannot load /usr/lib/apache2/lib/apache2/modules/mod_proxy_html.so into server: /usr/lib/apache2/lib/apache2/modules/mod_proxy_html.so: undefined symbol: htmlFreeParserCtxt
```

until You add a further line to apache2.conf:

```
LoadFile    /usr/lib/libxml2.so

LoadModule proxy_html_module  lib/apache2/modules/mod_proxy_html.so
```

To actually use the module mod_proxy_html my changes to commonapache2.conf are alltogether:

```
<IfModule mod_proxy.c>

    ProxyRequests Off

    ProxyPass /webcam/ http://webcam.local/

    ProxyPassReverse /webcam/ http://webcam.local/

    ProxyHTMLURLMap http://webcam.local /webcam

    SetOutputFilter  proxy-html

    ProxyHTMLURLMap  /      /webcam/

    ProxyHTMLURLMap  /webcam  /webcam

</IfModule>
```

This will let appear the whole LAN-internal webcam.local as the subdirectory /webcam/ of the Apache server.

This really works great, but will fail in the case (as with my webcam   :Sad:  ) when Javascript routines inside the web pages are accessing files with absolute instead of relative addressing.

mod_proxy_html seems not to be able to deal with this...

- Cocker :wqLast edited by Cocker68 on Tue Oct 05, 2004 8:04 pm; edited 1 time in total

----------

## bmichaelsen

```
ProxyRequests Off

ProxyPass /other-server-proxy http://192.168.1.66

RewriteEngine On

RewriteCond %{HTTP_HOST} ^example.com$

RewriteRule (.*) /other-server-proxy/$1 [P]

```

this is what i use to make the server at 192.168.1.66 visible as example.com outside of the LAN ...

----------

## Cocker68

@bmichaelsen: What would You do, if webpages on Your internal server had references like

```
<a href="/somepage.html">somepage</a>
```

Someone from extern klicking on it would get a 404 requesting http://example.com/somepage.html because the link inside the web-page is not rewritten with Your approach.

- Cocker :wq

----------

## bmichaelsen

 *Quote:*   

> Someone from extern klicking on it would get a 404

 

no. (Just tesed it to be sure). Works perfectly.

```
%{HTTP_HOST}!=URL
```

The only thing that is tricky is ssl stuff.....

----------

