custom 502 error page is ignored

Ruslan Ermilov ru at nginx.com
Mon Nov 26 08:41:39 UTC 2012


On Sun, Nov 25, 2012 at 09:52:43AM -0500, gus0253 wrote:
> Dear all,
> 
> I'm currently wondering why nginx ignores my custom 502 Bad Gateway page and
> instead serves the internal 502 error page.
> I'm using nginx version 1.2.4 and php-fpm 5.4.8
> 
> The behaivior occures every time and is reproducible:
> If I stop php-fpm and request an existing php file my custom 502 error page
> is shown, so everything is fine.
> But if I request a non existing php file nginx shows me the nginx internal
> 502 error page.
> 
> I don't know why my custom 502 error page is ignored, because it's a static
> html file.
> Do you have any tipps for me?

Querying index2.php results in error 404 handled by location "/404.html"
which in turn results in (recursive) error 502 if php-fpm is stopped.

http://nginx.org/r/recursive_error_pages

(Turn it on in the location "~* \.php$".)

> Part from the debug log:
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http script var: "/index2.php"
> 2012/11/25 15:29:09 [debug] 10777#0: *26 trying to use file: "/index2.php"
> "/usr/share/nginx/html/index2.php"
> 2012/11/25 15:29:09 [debug] 10777#0: *26 trying to use file: "=404"
> "/usr/share/nginx/html=404"
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http finalize request: 404,
> "/index2.php?" a:1, c:1
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http special response: 404,
> "/index2.php?"
> 2012/11/25 15:29:09 [debug] 10777#0: *26 internal redirect: "/404.html?"
> 2012/11/25 15:29:09 [debug] 10777#0: *26 rewrite phase: 0
> 2012/11/25 15:29:09 [debug] 10777#0: *26 test location: "/"
> 2012/11/25 15:29:09 [debug] 10777#0: *26 test location: "502.html"
> 2012/11/25 15:29:09 [debug] 10777#0: *26 test location: "404.html"
> 2012/11/25 15:29:09 [debug] 10777#0: *26 using configuration "=/404.html"
> ...
>  http run request: "/404.html?"
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http upstream check client, write
> event:1, "/404.html"
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http upstream recv(): -1 (11:
> Resource temporarily unavailable)
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http upstream request:
> "/404.html?"
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http upstream process header
> 2012/11/25 15:29:09 [error] 10777#0: *26 connect() failed (111: Connection
> refused) while connecting to upstream, client: 10.0.2.2, server: localhost,
> request: "GET /index2.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000",
> host: "127.0.0.1"
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http next upstream, 2
> 2012/11/25 15:29:09 [debug] 10777#0: *26 free rr peer 1 4
> 2012/11/25 15:29:09 [debug] 10777#0: *26 finalize http upstream request:
> 502
> 2012/11/25 15:29:09 [debug] 10777#0: *26 finalize http fastcgi request
> 2012/11/25 15:29:09 [debug] 10777#0: *26 free rr peer 0 0
> 2012/11/25 15:29:09 [debug] 10777#0: *26 close http upstream connection: 8
> 2012/11/25 15:29:09 [debug] 10777#0: *26 free: 0000000001F7C560, unused: 48
> 2012/11/25 15:29:09 [debug] 10777#0: *26 event timer del: 8: 1353853809503
> 2012/11/25 15:29:09 [debug] 10777#0: *26 reusable connection: 0
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http finalize request: 502,
> "/404.html?" a:1, c:1
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http special response: 502,
> "/404.html?"
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http set discard body
> 2012/11/25 15:29:09 [debug] 10777#0: *26 HTTP/1.1 502 Bad Gateway
> Server: nginx/1.2.4
> Date: Sun, 25 Nov 2012 14:29:09 GMT
> Content-Type: text/html
> Content-Length: 172
> Connection: keep-alive
> 
> 2012/11/25 15:29:09 [debug] 10777#0: *26 write new buf t:1 f:0
> 0000000001F385A8, pos 0000000001F385A8, size: 156 file: 0, size: 0
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http write filter: l:0 f:0 s:156
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http output filter "/404.html?"
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http copy filter: "/404.html?"
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http postpone filter "/404.html?"
> 0000000001F38778
> 2012/11/25 15:29:09 [debug] 10777#0: *26 write old buf t:1 f:0
> 0000000001F385A8, pos 0000000001F385A8, size: 156 file: 0, size: 0
> 2012/11/25 15:29:09 [debug] 10777#0: *26 write new buf t:0 f:0
> 0000000000000000, pos 000000000069B3E0, size: 120 file: 0, size: 0
> 2012/11/25 15:29:09 [debug] 10777#0: *26 write new buf t:0 f:0
> 0000000000000000, pos 000000000069A1A0, size: 52 file: 0, size: 0
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http write filter: l:1 f:0 s:328
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http write filter limit 0
> 2012/11/25 15:29:09 [debug] 10777#0: *26 writev: 328
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http write filter 0000000000000000
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http copy filter: 0 "/404.html?"
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http finalize request: 0,
> "/404.html?" a:1, c:1
> 2012/11/25 15:29:09 [debug] 10777#0: *26 set http keepalive handler
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http close request
> 2012/11/25 15:29:09 [debug] 10777#0: *26 http log handler
> 
> 
> Example configuration:
> 
> upstream php_fpm {
>   server 127.0.0.1:9000;
> }
> 
> server {
>   listen 80;
>   server_name localhost;
>   root /usr/share/nginx/html;
> 
>   error_log /var/log/nginx/default.log debug;
> 
>   location / {
>     index index.php index.html index.htm;
>   }
> 
>   error_page 404 /404.html;
>   error_page 502 /502.html;
>   location = /404.html {
>     fastcgi_intercept_errors on;
>     include /etc/nginx/fastcgi_params;
>     fastcgi_param SCRIPT_FILENAME $document_root/404.php;
>     fastcgi_index index.php;
>     fastcgi_pass php_fpm;
>   }
>   location = /502.html {
>   }
>   location ~* \.php$ {
>     try_files $uri =404;
>     fastcgi_intercept_errors on;
>     include /etc/nginx/fastcgi_params;
>     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
>     fastcgi_index index.php;
>     fastcgi_pass php_fpm;
>   }
> }
> 
> Best regards,
> Gus



More information about the nginx mailing list