Nginx 和 Gunicorn WSGI 变量
Nginx and Gunicorn WSGI Variables
我正在测试 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 变量?
Gunicorn documentation 建议您可以通过 HTTP header 指定 SCRIPT_NAME
,无需任何进一步解释。深入研究源代码发现它接受一个 non-standard header 实际上命名为 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
前缀。
我正在测试 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 变量?
Gunicorn documentation 建议您可以通过 HTTP header 指定 SCRIPT_NAME
,无需任何进一步解释。深入研究源代码发现它接受一个 non-standard header 实际上命名为 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
前缀。