Nginx不使用Gunicorn显示自定义404页+烧瓶
我正在尝试在我的网站上显示一个自定义404错误页面,但是似乎Nginx并未捕获404。相反,它显示了Gunicorn(Blask App)
nginx.conf的404页:
server {
listen 80 default_server;
server_name example.com www.example.com;
location / {
proxy_pass http://flask:8080/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
error_page 404 /notfound.html;
location /notfound.html {
root /var/www/html;
}
error_page 500 502 503 504 /maintenance.html;
location /maintenance.html {
root /var/www/html;
}
}
Blask App和Nginx都在单独的Docker容器上运行。
我有目的地将烧瓶应用程序放下以查看发生了什么事 当它重定向到504(超时)和维护。HTML出现。 - 工作正常。
但是在404错误而不是显示此自定义notfound.html
上,它显示404从烧瓶应用程序中找到
(404页面上没有任何nginx版本) 。
I'm trying to display a custom 404 error page on my site, but it seems that Nginx does not catch the 404. Instead, it shows a 404 page from Gunicorn(flask app)
nginx.conf:
server {
listen 80 default_server;
server_name example.com www.example.com;
location / {
proxy_pass http://flask:8080/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
error_page 404 /notfound.html;
location /notfound.html {
root /var/www/html;
}
error_page 500 502 503 504 /maintenance.html;
location /maintenance.html {
root /var/www/html;
}
}
Both flask app and Nginx are running on separate docker containers.
I purposefully brought the flask app down to see what happens, after a
while It redirects to 504(Timeout) and the maintenance.html appeared. - works fine.
But on a 404 error instead of displaying this custom notfound.html
, it displays a 404 Not Found
from Flask App (The 404 page did not had any nginx version on it).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
proxy_intercept_errors;
应该解决此问题。proxy_intercept_errors on;
should solve this problem.