Welcome! Log In Create A New Profile

Advanced

Passing errors to user received from upstream generated by POST requests

Posted by sentros 
Passing errors to user received from upstream generated by POST requests
August 30, 2018 08:15AM
Hi

I have a setup where nginx acts as a reverse proxy for two application servers and is configured to try the other application server if the first one fails. The problem is I can't pass errors generated by the application to the user in case it was generated by a POST request. Here's a scenario I'm facing:

1. User sends POST request to nginx
2. nginx passes said request to an upstream server
3. Upstream server responds with an HTTP 500 and a stack trace
4. nginx sends an HTTP 500 message to the user without the stack trace. Instead it contains a generic HTTP 500 html body

The scenario does not happen when a user send for example an HTTP PUT request. In that scenario the stack trace is passed along to the user. I understand nginx handles non-idempotent messages differently as is evident in the configuration parameters of proxy_next_upstream. If I add non-idempotent to proxy_next_upstream the stack trace is indeed passed on to the user but in these cases the POST request is passed to multiple upstreams in case of an error. This is not something I want to do.

Is there a way for nginx to pass the original error message from an upstream to a user when the error was generated by a POST request?

Here's the relevant parts of my configuration:

upstream webapp {
server 10.0.0.2:1234;
server 10.0.0.3:1234;
}

server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}

server {
listen 443 ssl;
server_name example.com;
ssl_certificate certs/example.crt;
ssl_certificate_key certs/example.key;

location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://webapp/;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;

}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 113
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready