Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#1303 closed defect (invalid)

Nginx should respect error_page directives

Reported by: wurde@… Owned by:
Priority: minor Milestone:
Component: other Version: 1.12.x
Keywords: Cc:
uname -a:
nginx -V: nginx version: nginx/1.12.0
built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
built with OpenSSL 1.0.2g 1 Mar 2016
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/run/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/body --http-proxy-temp-path=/var/lib/nginx/proxy --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-http_ssl_module --with-pcre-jit --with-http_gzip_static_module --with-http_gunzip_module --with-http_realip_module --with-http_geoip_module --with-http_v2_module --add-module=/usr/share/passenger/ngx_http_passenger_module

Description

I define a custom error page for 503 errors when putting my site into maintenance mode. It annoys me that this directive is not respected. The code below does not return custom error page.

location / {

if (-f /home/ubuntu/accreu/tmp/maintenance-on) {

return 503;

}

}

error_page 400 401 404 422 /404.html;
error_page 500 502 503 504 /500.html;

Change History (3)

comment:1 by Maxim Dounin, 3 years ago

Resolution: invalid
Status: newclosed

The if (-f /home/ubuntu/accreu/tmp/maintenance-on) ... in your configuration doesn't allow nginx to return configured error page file, and that's why provided configuration can't return custom error page. Fixing the configuration to do not check the maintanance file for error pages (for example, by introducing a separate location for the error page) will resolve this.

comment:2 by wurde@…, 3 years ago

Ok I'm aware that the 'if' block doesn't allow for sending the error page. Is there rational thinking behind this? I define the error page location /500.html, so why require I do that again?

comment:3 by Maxim Dounin, 3 years ago

When you define an error page /500.html, you define an URI which will be shown in case of an error. The URI is in turn processed much like any request within nginx, thus allowing to do various conditional processing, proxying to external servers and so on. The documentation contains some examples on how to use this to implement various complex request processing.

Note: See TracTickets for help on using tickets.