Opened 6 years ago

Closed 6 years ago

#1634 closed defect (fixed)

No response from nginx

Reported by: huisuiwyn@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.15.x
Keywords: Cc:
uname -a:
nginx -V: nginx version: nginx/1.15.4
built by gcc 7.2.0
built with OpenSSL 1.0.2l 25 May 2017
TLS SNI support enabled
configure arguments: --prefix=/var/www --conf-path=/etc/nginx/nginx.conf --sbin-path=/usr/sbin/nginx --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-log-path=logs/access.log --error-log-path=logs/error.log --http-client-body-temp-path=/var/www/cache/client_body_temp --http-proxy-temp-path=/var/www/cache/proxy_temp --http-fastcgi-temp-path=/var/www/cache/fastcgi_temp --http-scgi-temp-path=/var/www/cache/scgi_temp --http-uwsgi-temp-path=/var/www/cache/uwsgi_temp --user=www --group=www --with-http_gzip_static_module --with-http_ssl_module --with-http_stub_status_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module

Description

I have no responsa nginx from configuration followyn:

    server {
        listen 8080;

        location /test {
            error_page 404 =200 @err502;
        }

        location @err502 {
            return 502;
        }
    }
# curl 127.1:8080/test                                       
curl: (52) Empty reply from server

水雞

Change History (5)

comment:1 by Maxim Dounin, 6 years ago

Status: newaccepted

Thanks for reporting this. Please try the following patch:

# HG changeset patch
# User Maxim Dounin <mdounin@mdounin.ru>
# Date 1537055589 -10800
#      Sun Sep 16 02:53:09 2018 +0300
# Node ID bf985ba5a3a99e8f78a1beb0b0bed398c72b13f7
# Parent  87d2ea860f380dc8418c97c0163412f53c2d008e
Rewrite: removed r->err_status special handling (ticket #1634).

Trying to look into r->err_status in the "return" directive
makes it behave differently than real errors generated in other
parts of the code, and is an endless source of various problems.
This behaviour was introduced in 726:7b71936d5299 (0.4.4) with
the comment "fix: "return" always overrode "error_page" response code".
It is not clear what it is expected to fix, but there are several
cases which are broken due to this change, some previously fixed
(4147:7f64de1cc2c0).

In ticket #1634, the problem is that when r->err_status is set to
a non-special status code, it is not possible to return an answer
by simply returning r->err_status.  If this is the case, the only
option is to return script's e->status instead.  An example
configuration:

    location / {
        error_page 404 =200 /err502;
        return 404;
    }

    location = /err502 {
        return 502;
    }

After the change, such a configuration will properly return
standard 502 error, much like it happens when a 502 error is
generated by proxy_pass.

This also fixes the following configuration to properly close
connection as clearly requested by "return 444":

    location / {
        error_page 404 /close;
        return 404;
    }

    location = /close {
        return 444;
    }

Previously, this required "error_page 404 = /close;" to work
as intended.

diff --git a/src/http/modules/ngx_http_rewrite_module.c b/src/http/modules/ngx_http_rewrite_module.c
--- a/src/http/modules/ngx_http_rewrite_module.c
+++ b/src/http/modules/ngx_http_rewrite_module.c
@@ -180,15 +180,7 @@ ngx_http_rewrite_handler(ngx_http_reques
         code(e);
     }
 
-    if (e->status < NGX_HTTP_BAD_REQUEST) {
-        return e->status;
-    }
-
-    if (r->err_status == 0) {
-        return e->status;
-    }
-
-    return r->err_status;
+    return e->status;
 }
 
 

comment:2 by huisuiwyn@…, 6 years ago

It doesn't work for me. With your patch nginx returns index page instead of 502 page.

in reply to:  2 comment:3 by Maxim Dounin, 6 years ago

Replying to huisuiwyn@…:

It doesn't work for me. With your patch nginx returns index page instead of 502 page.

Please double-check to make sure there are no other factors that results in index page being returned in your configuration. If it is indeed the case, please provide debug log.

comment:4 by Maxim Dounin <mdounin@…>, 6 years ago

In 7355:b64adc956643/nginx:

Rewrite: removed r->err_status special handling (ticket #1634).

Trying to look into r->err_status in the "return" directive
makes it behave differently than real errors generated in other
parts of the code, and is an endless source of various problems.
This behaviour was introduced in 726:7b71936d5299 (0.4.4) with
the comment "fix: "return" always overrode "error_page" response code".
It is not clear if there were any real cases this was expected to fix,
but there are several cases which are broken due to this change, some
previously fixed (4147:7f64de1cc2c0).

In ticket #1634, the problem is that when r->err_status is set to
a non-special status code, it is not possible to return a response
by simply returning r->err_status. If this is the case, the only
option is to return script's e->status instead. An example
configuration:

location / {

error_page 404 =200 /err502;
return 404;

}

location = /err502 {

return 502;

}

After the change, such a configuration will properly return
standard 502 error, much like it happens when a 502 error is
generated by proxy_pass.

This also fixes the following configuration to properly close
connection as clearly requested by "return 444":

location / {

error_page 404 /close;
return 404;

}

location = /close {

return 444;

}

Previously, this required "error_page 404 = /close;" to work
as intended.

comment:5 by Maxim Dounin, 6 years ago

Resolution: fixed
Status: acceptedclosed

Fix committed, thanks for reporting this.

Note: See TracTickets for help on using tickets.