【问题标题】:Nginx and Gunicorn WSGI VariablesNginx 和 Gunicorn WSGI 变量
【发布时间】:2020-12-04 18:12:16
【问题描述】:

我正在测试 Gunicorn 作为 uWSGI 的替代品。在 Gunicorn 实例前面设置了一个 Nginx 反向代理。不使用 uWSGI 的结果是我不得不使用 Nginx 的 proxy_pass 而不是 uwsgi_pass。使用uwsgi_pass,我可以使用uwsgi_param 覆盖PATH_INFOSCRIPT_NAME WSGI 变量。 proxy_pass 没有等效指令。您如何为 Gunicorn 等符合 WSGI 的应用服务器设置 proxy_pass 的这些 WSGI 变量?

【问题讨论】:

  • 认为您可能正在寻找proxy_set_header 触及in this thread...特别是:With proxy_pass - request is forwarded as HTTP request to upstream server. And with proxy_set_header headers and their value to be passed can be set. With uwsgi_pass request is forwarded via uwsgi binary protocol. It is not http, it has no 'headers', instead it has parameters to be passed by uwsgi_param (if parameter name is prefixed with HTTP_ - it is available as a header in wsgi app).
  • @v25 我不确定proxy_set_header 是否是合适的替代品。根据PEP 3333,HTTP 标头将被设置为名为@9​​87654335@ 的WSGI 变量。我正在寻找专门设置SCRIPT_NAME 和可能PATH_INFO。我想 Gunicorn 可能支持诸如 X-WSGI-... 之类的标头来设置这些标头,但我还没有找到与此详细信息相关的文档。

标签: python nginx gunicorn wsgi


【解决方案1】:

Gunicorn documentation 建议您可以通过 HTTP 标头指定 SCRIPT_NAME 而无需任何进一步解释。挖掘源代码发现它接受一个实际上名为SCRIPT_NAME 的非标准头文件。以下可用于为 Gunicorn 设置SCRIPT_NAME

proxy_set_header SCRIPT_NAME /myapp;

PATH_INFO 无法设置。但是,在我的情况下,不需要为 Gunicorn 设置 PATH_INFO,因为它会自动从 PATH_INFO 中删除 SCRIPT_NAME 前缀。使用 uWSGI 我必须覆盖 PATH_INFO 以去除 SCRIPT_NAME 前缀。

【讨论】:

    猜你喜欢
    • 2012-08-17
    • 2012-09-09
    • 2017-03-28
    • 1970-01-01
    • 2016-04-24
    • 2013-07-12
    • 2020-08-10
    • 2012-06-24
    • 2012-05-30
    相关资源
    最近更新 更多