How to server static files + proxy context

poussma picture poussma · Dec 12, 2014 · Viewed 9.5k times · Source

I am wondering how to configure my httpd server to serves the following pages:

My need is to serve static content located in my /var/www/static when url is /context/static and to proxy the remaining to a tomcat server

In this order:

/context/static/* --> files served by httpd
/context/*        --> resources served by tomcat

I have tried to rewrite /context/static/* to a folder pointing to my /var/www/static and added the ProxyPath directive for the remaining but I can't get it working.

What are the best practices and how to achieve that ?

Thanks in advance

Answer

poussma picture poussma · Dec 12, 2014

Well, in fact it is quiet easy...

Having such folders configured:

/var/www/static/
               |-  css/*
               |-  js/*
                \  medias/*

The following httpd configuration will redirect static/* to the /var/www and the rest will be proxied

# first rewrite for statics
RewriteEngine On
RewriteRule ^/context/static/(.+)$ /static/$1

# then proxy remaining...
ProxyPass               /context  http://127.0.0.1:8080/context
ProxyPassReverse        /context  http://127.0.0.1:8080/context