Return JSON for 404 error instead of html

justink101 nginx-forum at
Wed May 14 22:38:45 UTC 2014

Noticed that the proxy request response headers are being thrown away in our
404 block. Note that the proxied request is returning 404. If I try and
fetch a header that I know is being returned from the proxy it is

location @four_o_four {
    more_set_headers "X-Host: $sent_http_x_host";
    return 404 '{
    "error": {
	"status_code": 404,
        "status": "Not Found",
        "message": "The requested resource does not exist."

In our block example,x-host is being returned from the proxy response, but
not visible in the @four_o_four location block. Any idea why?

Posted at Nginx Forum:,250033,250096#msg-250096

More information about the nginx mailing list