【发布时间】:2020-06-12 04:02:10
【问题描述】:
我使用 NGINX 作为 gunicorn 应用服务器的反向代理。当出现服务器错误(未找到 url、请求超时等)时,响应将作为 html 返回。我熟悉 NGINX 的 error page directive 并且我尝试在服务器块中放置一个错误指令,该指令转发到我的应用程序服务器,如下所示,但响应仍以 html 形式返回。有什么想法吗?
server {
server_name rtj.foo.com;
client_max_body_size 10M;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/ubuntu/api;
}
error_page 404 /404.html;
location /404.html{
return 404 '{"error": {"status_code": 404,"status": "Not Found"}}';
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
【问题讨论】:
标签: nginx http-headers gunicorn