Serve web application error messages from Http server [closed]
- by licorna
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?