【问题标题】:errorhandler in flask and nginx server烧瓶和 nginx 服务器中的错误处理程序
【发布时间】:2016-01-28 17:34:30
【问题描述】:

我在我的烧瓶应用程序中使用以下错误处理程序

@app.errorhandler(413)
def error413(e):
    return render_template('error413.html'), 413

如果发生错误 413(文件大小太大),则会显示错误页面。这在我的本地主机上运行良好,但在服务器上我得到了 nginx 413 错误页面。

413 Request Entity Too Large
nginx/1.4.6 (Ubuntu)

在错误处理方面,nginx 服务器和 localhost 有什么不同吗? 我将gunicorn与nginx一起使用...... 谢谢 卡尔

【问题讨论】:

    标签: python nginx flask


    【解决方案1】:

    默认情况下,nginx 会捕获 HTTP 错误代码。出于安全目的,这是一件好事。

    可以禁用此行为,您可以设置uwsgi_intercept_errors off

    http://nginx.org/en/docs/http/ngx_http_uwsgi_module.html#uwsgi_intercept_errors

    您可以使用由 nginx 提供的自定义静态错误页面。示例:

    error_page 413 /custom_413.html;
    
    location = /custom_413.html {
        root /usr/share/nginx/html;
        internal;
    }
    

    只需将其设置为您要处理的所有错误代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-27
      • 2021-03-31
      • 2014-07-02
      • 2014-08-06
      • 2019-04-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      相关资源
      最近更新 更多