Nginx不提供我的error_page [英] nginx not serving my error_page
问题描述
我有一个由Unicorn托管的Sinatra应用程序,并且在它前面是nginx.当Sinatra应用程序出现错误(返回500)时,我想提供一个静态页面,而不是默认的内部服务器错误".我有以下nginx配置:
I have a Sinatra application hosted with Unicorn, and nginx in front of it. When the Sinatra application errors out (returns 500), I'd like to serve a static page, rather than the default "Internal Server Error". I have the following nginx configuration:
server {
listen 80 default;
server_name *.example.com;
root /home/deploy/www-frontend/current/public;
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 5;
proxy_read_timeout 240;
proxy_pass http://127.0.0.1:4701/;
}
error_page 500 502 503 504 /50x.html;
}
其中存在error_page指令,我已将sudo设置为www-data(Ubuntu),并验证了我可以cat
该文件,因此这不是权限问题.使用上面的配置文件和service nginx reload
,我在出错时收到的页面仍然是相同的内部服务器错误".
The error_page directive is there, and I have sudo'd as www-data (Ubuntu) and verified I can cat
the file, thus it's not a permission problem. With the above config file, and service nginx reload
, the page I receive on error is still the same "Internal Server Error".
我怎么了?
推荐答案
error_page
处理nginx生成的错误.默认情况下,nginx将返回代理服务器返回的所有内容,而与http状态代码无关.
error_page
handles errors that are generated by nginx. By default, nginx will return whatever the proxy server returns regardless of http status code.
您要查找的是 proxy_intercept_errors
此指令确定nginx是否将拦截HTTP响应 状态码为400或更高.
This directive decides if nginx will intercept responses with HTTP status codes of 400 and higher.
默认情况下,所有响应将从代理服务器按原样发送.
By default all responses will be sent as-is from the proxied server.
如果将其设置为on,则nginx将截获以下状态代码: 由error_page指令显式处理.有状态的回应 与error_page指令不匹配的代码将按原样发送 从代理服务器.
If you set this to on then nginx will intercept status codes that are explicitly handled by an error_page directive. Responses with status codes that do not match an error_page directive will be sent as-is from the proxied server.
这篇关于Nginx不提供我的error_page的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!