Opened 8 years ago

Closed 8 years ago

#1103 closed defect (invalid)

return code can not use customization setting

Reported by: leo52668@… Owned by:
Priority: minor Milestone:
Component: other Version: 1.11.x
Keywords: error_page return Cc:
uname -a: Linux singa-vm-01 3.10.0-327.36.1.el7.x86_64 #1 SMP Sun Sep 18 13:04:29 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.11.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx/nginx --with-debug --with-cc-opt='-DNGX_LUA_USE_ASSERT -DNGX_LUA_ABORT_AT_PANIC -O2' --add-module=../ngx_devel_kit-0.3.0 --add-module=../iconv-nginx-module-0.14 --add-module=../echo-nginx-module-0.60 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.31 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.06 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.6 --add-module=../ngx_lua_upstream-0.06 --add-module=../headers-more-nginx-module-0.31 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.17 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.14 --add-module=../rds-csv-nginx-module-0.07 --with-ld-opt=-Wl,-rpath,/etc/nginx/luajit/lib --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_v2_module --with-ipv6 --with-pcre-jit

Description

I tried two setting, for the issue.

No.1 -> it return system default 406 page.

if ($request_method = GET) {
    return 406;
}
error_page 406 /406.html;
location = /406.html {
    root html;
    internal;
}

No.2 -> it will return the custom 406 page

location /test {
    return 406;
}
error_page 406 /406.html;
location = /406.html {
    root html;
    internal;
}

So, could you tell me what are the different between these?

Change History (1)

comment:1 by Maxim Dounin, 8 years ago

Resolution: invalid
Status: newclosed

The problem with the first snippet is that return 406 is executed twice:

  1. during initial execution of rewrite module directives specified at server level;
  2. during execution of rewrite module directives for the /406.html (after error_page redirection).

Since the error is returned for the second time, and recursive_error_pages is off, nginx returns an internal version of the error page.

An obvious workaround is to restrict return to a particular location instead of placing it on the server level, as it is done in your second example.

More details about rewrite module directives can be found here.

Note: See TracTickets for help on using tickets.