Apache vhost + proxy clamping revisited
Found a simple solution to the requirement in my last post:
In order to let apache proxy all requests to a backend-server but also serve some static files from a url-alias, this will be sufficient:
<VirtualHost 22.214.171.124: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/(.*) /path/to/static/files/$1 [QSA,L] </VirtualHost>
No need to let apache listen on another localhost-port and act as proxy front- and backendserver the same time. This is much easier…
The revisited and much nicer apache configuration looks like this:
Apache 126.96.36.199:80 |-----> /static/* served by apache itself from /path/to/static/files/ |-----> /* |----> Tomcat 127.0.0.1:8080 application server
The mistake i made in the first place was not to rewrite requests to /static/* to a local folder which apache could serve but to proxy those requests to another apache backend-server which was configured to serve such static files only.
Lesson learned: apache2-mod-rewrite as swiss-army-knife for the rescue.