tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier>
Subject Re: Need Information regarding Apache Webserver static file configuration
Date Thu, 05 Dec 2013 18:11:59 GMT
Tapajyoti Roybarman wrote:
> Hi Andre,
> I apologize for not following the mailing rule. Actually this is the first 
> time that I am taking the help of such a forum.
> Before I begin asking you anything I want to thank you for such a detailed 
> explanation.
> To begin with, answer to your question - "why do you want to serve these 
> files from Apache httpd, instead of letting Tomcat do it?" I am planning 
> to use Apache httpd as a Load Balancer. And to improve the performance of 
> my application, I want to serve the static content from apache itself.
> Now, as per your suggestion I have modified the entries of httpd.conf file 
> to this.
> ProxyPassMatch ^/.*\.(gif|jpg|css|png)$! http://localhost:8080/
> ProxyPassMatch ^/(.*\.jsp)$ http://localhost:8080/$1
> ProxyPassReverse / http://localhost:8080/
> ProxyPassMatch ^/.*\.(gif|jpg|css|png)$! http://localhost:8080/ - By using 
> this setting I am able to serve static files from apache. I have kept my 
> files under DocumentRoot as per your suggestion.
> ProxyPassMatch ^/(.*\.jsp)$ http://localhost:8080/$1 - If I am not using 
> this. I am getting a page not found error for my page Login.jsp present 
> inside Tomcat/Webapps/MyApplication. When I am using this setting I am 
> able to reach to the page Login.jsp.
> Now, the probelm is, the Login.jsp actually sends the request to a servlet 
> to complete the login functionality. I am not able to reach to that 
> servlet using the above settings. The URL  is - 
> http://localhost/MyApplication/servlet/login
> What should I add in the httpd.conf to achieve this?

Assuming that all the URLs which contain "/servlet/" are to be forwarded to Tomcat,
you could use something like :

ProxyPassMatch ^/.*\.(gif|jpg|css|png)$! http://localhost:8080/
ProxyPassMatch ^/(.*\.jsp)$ http://localhost:8080/$1
ProxyPassMatch ^/(.*/servlet/.*)$ http://localhost:8080/$1

ProxyPassReverse / http://localhost:8080/

Note : still be careful of the order of the directives.  As indicated in the corresponding

mod_proxy documentation, httpd evaluates each Proxy* directive in turn, from top to 
bottom, and the first one that matches "wins the day".
For example, if you had this order :

ProxyPassMatch ^/(.*\.jsp)$ http://localhost:8080/$1
ProxyPassMatch ^/(.*/servlet/.*)$ http://localhost:8080/$1
ProxyPassMatch ^/.*\.(gif|jpg|css|png)$! http://localhost:8080/

then a URL like
would be proxied to Tomcat, because the line
ProxyPassMatch ^/(.*/servlet/.*)$ http://localhost:8080/$1
would match before the line
ProxyPassMatch ^/.*\.(gif|jpg|css|png)$! http://localhost:8080/

As I recall, httpd has an internal flag that means "proxy this URL" or "don't proxy this 
URL".  As soon as one of the expressions in a Proxy* statement matches, that flag is set 
(one way or the other), and no further evaluation of Proxy* statements takes place.

That also means that if you happen to know that there are many more URLs containing 
"/servlet/" than there are ending in ".jsp", you could do some (very small) optimisation 
by doing this :
ProxyPassMatch ^/.*\.(gif|jpg|css|png)$! http://localhost:8080/
ProxyPassMatch ^/(.*/servlet/.*)$ http://localhost:8080/$1
ProxyPassMatch ^/(.*\.jsp)$ http://localhost:8080/$1

Alternatively again : if, once you have "filtered out" all URLs ending in 
(gif|jpg|css|png), you know that all the remaining ones that start with "/MyApplication" 
should be forwarded to Tomcat, then you could use :

ProxyPassMatch ^/.*\.(gif|jpg|css|png)$ ! http://localhost:8080/
ProxyPassMatch ^/MyApplication http://localhost:8080/MyApplication

and that would take care of both
and many others.

It's fun playing with..
And mod_rewrite is even more fun.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message