Apache VHOST and PROXY clamping

Imagine an apache2 vhost that acts as a proxy-frontend to a tomcat backend/application server. The apache vhost is listening on a public IP on port 80, while tomcat is listening on port 8080 on localhost only.

The appropriate working vhost for this situation would look like this:

<VirtualHost 11.22.33.44:80>
    ServerName www.example.com

    ProxyRequests     Off
    ProxyPreserveHost On

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    ProxyPass         / http://localhost:8080/
    ProxyPassReverse  / http://localhost:8080/

</VirtualHost>

The customer wants to serve additional files from the same vhost with apache. Those files are static files and will serve some kind of addition to the application servers ressources - i.e. some more fancy icons…

My solution to this would be to fork the apache to listen on localhost at a hidden port, forward all requests to the static files to this proxy backend.

The apache configuration will look like this:

Apache 11.22.33.44:80
    |-----> /static/*
        |-----> Apache 127.0.0.1:8888  /path/to/static/files/
    |-----> /*
        |-----> Tomcat 127.0.0.1:8080  application server

I need to expand the vhost file above to look like this:

<VirtualHost 11.22.33.44:80>
    ServerName www.example.com

    ProxyRequests     Off
    ProxyPreserveHost On

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    ProxyPass         / http://localhost:8080/
    ProxyPassReverse  / http://localhost:8080/

    RewriteEngine On
    RewriteRule ^/static/(.*) http://127.0.0.1:8888/$1 [P,QSA,L]

</VirtualHost>

Listen 8888
NameVirtualHost 127.0.0.1:8888
<VirtualHost 127.0.0.1:8888>
    ServerName 127.0.0.1

    DocumentRoot /path/to/static/files/
    <Directory /path/to/static/files/>
        Options FollowSymLinks -Indexes IncludesNoExec
        AllowOverride All
    </Directory>

</VirtualHost>

Why you might ask am i doing this. Because adding a alias or RewriteRule is not sufficient enough, every request would be still sent to the backend server (tomcat).

A bit complicated though. And mostly overkill as i found out a day later. See my other article here.