fastcgi_pass / error page /error code in HTTP rsp

nginxuser100 nginx-forum at nginx.us
Mon Jun 8 19:14:00 UTC 2015


Hi, I would like nginx to map a fastcgi error response a static error page,
and  include the HTTP error code in its HTTP response header; e.g.
1. have nginx return the proper error code in its header to the client.
2. have nginx return the proper error page based on the fastcgi_pass
server's response error code.
For example, if the fastcgi server returns '400 Bad Request', I would like
NGINX to return "Status code: 400" along with the bad request html static
error page.

Is #2 feasible when fastcgi_pass is used? I was not able to do it, unless I
used error code 302, a redirect. In other words, the only way I got nginx to
return a specific error page was to have the fastcgi server respond with a
redirect
    "Status: 302 Found\r\n"
    "Location: /<path>/badRequest.html\r\n"
The problem with this method was that the error code (400 for example) did
not appear in the HTTP response of the error page (requirement #1 was not
met).

How can I have nginx/fastcgi_pass return an error page with the HTTP error
code (400 for example) appear in the HTTP header? My fastcgi server response
did include 'Status' in the fastcgi response.
I tried not using the redirect 302 method but my attempts failed; I had the
following inside the server block or inside the location/fastcgi_pass block
of  nginx.conf:

        error_page 400 = /bad_request.html;

        location = /bad_request.html {
           try_files /<path>/bad_request.html 50x.html;
        }
I tried the 'internal' directive also though I was not sure of its usage as
the path of the html error page was not specified.
Any help on how to get nginx to return the error code in the HTTP header
response and an error page when fastcgi is used would be greatly
appreciated, thank you!

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,259436,259436#msg-259436



More information about the nginx mailing list