I have an Apache web server for static content and a Tomcat server with some servlets.
Apache serves the static resources included in the WAR but from an external directory copied from the deployed WAR directory, not from the deployed WAR directory itself.
When Apache receives a backend request it routes it to Tomcat:
ProxyPass /backend ajp://localhost:8009/backend
ProxyPassReverse /backend ajp://localhost:8009/backend
My problem is that Tomcat is also serving the static resources, so for example, these two requests are serving the same web page:
http://foo.com/page.html
http://foo.com/backend/page.html
How can I prevent Tomcat from serving the static resources?
I can delete the static content from the deployed war directory, but I'm looking for a better way.
You can try moving the static resources to somewhere inside the WEB-INF folder. From the Oracle servlet specification:
The WEB-INF directory is not part of the public document tree of the application. No file contained in the WEB-INF directory can be served directly to a client by the container. However, the contents of the WEB-INF directory are visible to servlet code using the getResource and getResourceAsStream() method calls on the ServletContext or includes/forwards using the RequestDispatcher.
Your script can still copy the reources from your WAR, which is just an archive of files. But these files will not be accessible anymore directly from your WAR.