We have setup like this:
httpd <-> mod_jk (Tomcat)
httpd is configured to forward all request to URL /app* to mod_jk. httpd is configured with custom error pages for HTTP errors 404, 500 etc.
If user enters URL, http://hostname/non-existing-page
- then httpd's custom 404 error page is displayed.
If user enters URL, http://hostname/app-blabblah
- then, Tomcat's 404 error page is displayed. The application hosted at /app can deal with 404 errors if it is something like /app/non-existentpage. But context /app-blablah does not resolve to any war file on Tomcat, and hence results in Tomcat's 404 error page.
We are using stripped down version of Tomcat, its webapps folder has only app.war
.
I have been asked to not display Tomcat 404 error page as it reveals the fact that app is hosted on Tomcat and also displays Tomcat's version.
If anyone can tell me how to:
PS: I am not at liberty to point only /app/* to mod_jk, as we sometimes deploy other wars that start with app for debugging purposes - for e.g. app-debug.war.
Update: I am changing mod_jk workers.properties to forward only /app/* to Tomcat.
To answer your question :
- Add custom 404 error page for Tomcat when it has to deal with URLs that represents non-existing context.
And respecting your initial constraint :
I am not at liberty to point only /app/* to mod_jk, as we sometimes deploy other wars that start with app for debugging purposes - for e.g. app-debug.war.
The simplest solution is to use a ROOT webapp folder. However, and to respect your other condition to keep your webapps folder minimalist, you don't have to keep anything in your ROOT webapp folder but your custom error page.
With this configuration, you just have to add in your $CATALINA_BASE/conf/web.xml
<error-page>
<error-code>404</error-code>
<location>/general-error.html</location>
</error-page>
Or anything that fits best what you want. (Here, you can use the same error custom page than your app.war and end users will not see the difference).
The result is :
Situation 1 : http://hostname/non-existing-page
Situation 2 : http://hostname/app/non-existing-page
Situation 3 : http://hostname/app-dummy-url
In you edit, you deleted your constraint and are now able to :
chang(e) mod_jk workers.properties to forward only /app/* to Tomcat.
Well in this configuration, you will have the same result as the alternative you wanted :
- Or configure httpd such that if it sees that Tomcat is returning 404 error, it renders its own custom 404 error page.
But if you still want to use debug war file such as you mentioned in your question (app-debug.war), you will need to modify your httpd configuration (worker.properties and probably your VirtualHosts as well) everytime and/or let debug configuration in those files. As it doesn't seems appropriate for a production environment, using a folder ROOT in Tomcat containing only custom pages seems the best solution here IMO.