Serve web application error messages from Http server
Posted
by
licorna
on Server Fault
See other posts from Server Fault
or by licorna
Published on 2010-12-27T18:41:58Z
Indexed on
2010/12/27
19:55 UTC
Read the original article
Hit count: 226
I have nginx as a http server with tomcat as a backend (using proxy_pass). It works great but I want to define my own error pages (404, 500, etc.) and that they are served by nginx and not tomcat. For example I have the following resource:
https://domain.com/resource
which doesn't exist. If I [GET] that URL then I get a Not Found message from Tomcat and not from nginx.
What I want is that every time Tomcat responds with a 404 (or any other error message) nginx sends itself a message to the user: some html file accessible by nginx.
The way I have my nginx server configured is very easy, just:
location / {
proxy_pass http://localhost:8080/<webapp-name>/;
}
And I've configured port 8080, which is tomcat, as not accessible from outside this machine.
I don't think that using different location
directives in nginx configuration will work, because there are some resources that depend on the URL:
https://domain.com/customer/<non-existent-customer-name>/[GET]
Will always return 404 (or any other error message), while:
https://domain.com/customer/<existent-customer>/[GET]
Will return anything different from 404 (the customer exists).
Is there any way of serving Tomcat (Application Server) error messages with Nginx (http Server)? To check the message sent by the proxy_pass
directive and act upon it?
© Server Fault or respective owner