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.
have nginx return the proper error code in its header to the client.
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: //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:
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!
On Mon, Jun 08, 2015 at 03:14:00PM -0400, nginxuser100 wrote:
used error code 302, a redirect. In other words, the only way I got nginx to
did include ‘Status’ in the fastcgi response.
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!
Thank you Maxim, that was what I was looking for. However, it is still
not
returning the static error page. Does nginx expect a certain response
format
from the fcgi server? I tried:
“HTTP/1.1 400 Bad Request\r\nStatus: 400 Bad Request\r\n”;
and
“HTTP/1.1 400 Bad Request”;
The nginx.conf has:
root …;
location xxx {
include fastcgi_params;
fastcgi_pass …;
error_page 400 /my_bad_request; ← inside or outside this
location block didn’t make a difference
fastcgi_intercept_errors on;
}
Hi, I expected fastcgi_intercept_errors to return a static error page
AND to
have include the HTTP error code (e.g. 400) in the HTTP response header.
From what I see, it returns the static error page but with 200 OK.
Is it the expected behavior?
If yes, is there a way to have nginx return the error page and the error
code to the client?
Thank you!
Can you think of a way of rephrasing the documentation so that it would
have been clearer to you, so that the next person will not have the
same problem?
What happens when you leave out the “=” and reload the config?
Is it the expected behavior?
It is what you have configured nginx to do, so yes.
If yes, is there a way to have nginx return the error page and the error
code to the client?
Configure it according to the “common” examples in the documentation,
not according to the special-case examples.
I also tried
fastcgi_pass_header Status;
along with the fastcgi_intercept_errors directive. NGINX still returned
200
OK instead of the 400 sent by the fastcgi server.
Posted at Nginx Forum:
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.