【发布时间】:2020-12-04 18:12:16
【问题描述】:
我正在测试 Gunicorn 作为 uWSGI 的替代品。在 Gunicorn 实例前面设置了一个 Nginx 反向代理。不使用 uWSGI 的结果是我不得不使用 Nginx 的 proxy_pass 而不是 uwsgi_pass。使用uwsgi_pass,我可以使用uwsgi_param 覆盖PATH_INFO 和SCRIPT_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 标头将被设置为名为@987654335@ 的WSGI 变量。我正在寻找专门设置SCRIPT_NAME和可能PATH_INFO。我想 Gunicorn 可能支持诸如X-WSGI-...之类的标头来设置这些标头,但我还没有找到与此详细信息相关的文档。
标签: python nginx gunicorn wsgi