Help with nginx second request

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Help with nginx second request

Эмануил Кант
Hi all,
I would really appreciate it if you could help me with nginx.

The situation is:
Nginx (v. 1.14.2) redirects the request to the application server. In case this request with the POST method and the application server gives an error code 500, the response is transmitted to the client.
But nginx then makes a second request. Is there any way to disable execution of the second request by nginx?
Many thanks in advance.

Here is a part of nginx file:

#Makes upstream to the branch with response code 500
upstream test5 {
       server 127.0.0.1:90;
       keepalive 20;
}

#virtualhost that issues response code 500;
server {
   listen 90 default_server;
   server_name localhost;
   root /home/jetty/www;

       location @intercept_disabled {
               proxy_intercept_errors off;
               proxy_pass http://test5;
       }

   location /test500 {
       return 500;
       error_page 500 /500.html;
   }
}

# Redirection to virtualhost that issues response code 500;
       location /test500 {
           proxy_pass http://test5;
       }

================================
Request and responses:
================================
curl -i -X POST localhost/test500

HTTP/1.1 500 Internal Server Error
Server: nginx
Date: Wed, 13 Nov 2019 14:21:25 GMT
Content-Type: text/html
Content-Length: 13
Connection: close
ETag: "5dcbd0b0-d"
ERROR 500 page.


ngrep -qiltW byline -s 1000 -c 1024 -d lo '' port 90

T 2019/11/13 14:25:08.751892 127.0.0.1:44416 -> 127.0.0.1:90 [AP] #4
POST /test500 HTTP/1.1.
X-Forwarded-For: 127.0.0.1.
Host: localhost.
X-Forwarded-Proto: http.
User-Agent: curl/7.58.0.
Accept: */*.

T 2019/11/13 14:25:08.752038 127.0.0.1:90 -> 127.0.0.1:44416 [AFP] #6
HTTP/1.1 500 Internal Server Error.
Server: nginx.
Date: Wed, 13 Nov 2019 14:25:08 GMT.
Content-Type: text/html.
Content-Length: 13.
Connection: close.
ETag: "5dcbd0b0-d".
ERROR 500 page.

T 2019/11/13 14:25:08.752139 127.0.0.1:44418 -> 127.0.0.1:90 [AP] #12
POST /test500 HTTP/1.1.
X-Forwarded-For: 127.0.0.1.
Host: localhost.
X-Forwarded-Proto: http.
User-Agent: curl/7.58.0.
Accept: */*.

T 2019/11/13 14:25:08.752221 127.0.0.1:90 -> 127.0.0.1:44418 [AFP] #14
HTTP/1.1 500 Internal Server Error.
Server: nginx.
Date: Wed, 13 Nov 2019 14:25:08 GMT.
Content-Type: text/html.
Content-Length: 13.
Connection: close.
ETag: "5dcbd0b0-d".
ERROR 500 page.

So, in the response we see that nginx makes second request.

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Help with nginx second request

Maxim Dounin
Hello!

On Wed, Nov 13, 2019 at 04:38:54PM +0200, Эмануил Кант wrote:

> Hi all,
> I would really appreciate it if you could help me with nginx.
>
> The situation is:
> Nginx (v. 1.14.2) redirects the request to the application
> server. In case this request with the POST method and the
> application server gives an error code 500, the response is
> transmitted to the client.
> But nginx then makes a second request. Is there any way to
> disable execution of the second request by nginx?
> Many thanks in advance.
>
> Here is a part of nginx file:
>
> #Makes upstream to the branch with response code 500
> upstream test5 {
>        server 127.0.0.1:90;
>        keepalive 20;
> }
>
> #virtualhost that issues response code 500;
> server {
>    listen 90 default_server;
>    server_name localhost;
>    root /home/jetty/www;
>
>        location @intercept_disabled {
>                proxy_intercept_errors off;
>                proxy_pass http://test5;
>        }
>    location /test500 {
>        return 500;
>        error_page 500 /500.html;
>    }
> }
>
> # Redirection to virtualhost that issues response code 500;
>        location /test500 {
>            proxy_pass http://test5;
>        }

What else is configured in the server{} block with "location
/test500"?

Results you provide (that is, two duplicate requests) and the
unneeded "location @intercept_disabled" in the first server
suggests that you've configured proxy_intercept_errors and
"error_page 500" with a name-based location with additional
proxy_pass to the same server.  And this is what causes duplicate
requests - because this is exactly what you've asked nginx to do.
An obvious solution is to remove this error handling or change it
to something different.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx