不需要的 HTTPS ->使用 nginx 进行 HTTP 重定向 + uwsgi +烧瓶应用程序
我有一个 flask 应用程序,由 uwsgi,使用 nginx 作为 uwsgi 的反向代理,使用内置的 uwsgi 代理模块。每当我访问重定向到另一个页面的页面时,Location 标头都会指向非 HTTPS URL。例如:
$ socat openssl:my-web-server:443 stdio
GET / HTTP/1.0
Host: my-web-server
HTTP/1.1 302 FOUND
Server: nginx/1.0.4
[...]
Location: http://my-web-server/login
我的 nginx 配置如下所示:
server {
listen 80;
listen 443 ssl;
server_name my-web-server;
charset utf-8;
ssl_certificate /etc/nginx/certs/server.pem;
ssl_certificate_key /etc/nginx/certs/server.key;
location / {
uwsgi_pass unix:/tmp/uwsgi.sock;
include uwsgi_params;
}
}
I have a flask app, hosted by uwsgi, with nginx as a reverse proxy to uwsgi, using the built-in uwsgi proxy module. Whenever I visit a page that redirects to another page, the Location header points to a non-HTTPS URL. For example:
$ socat openssl:my-web-server:443 stdio
GET / HTTP/1.0
Host: my-web-server
HTTP/1.1 302 FOUND
Server: nginx/1.0.4
[...]
Location: http://my-web-server/login
My nginx config looks like this:
server {
listen 80;
listen 443 ssl;
server_name my-web-server;
charset utf-8;
ssl_certificate /etc/nginx/certs/server.pem;
ssl_certificate_key /etc/nginx/certs/server.key;
location / {
uwsgi_pass unix:/tmp/uwsgi.sock;
include uwsgi_params;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
uwsgi 需要传递用于服务请求的方案(http 或 https),以便写入正确的 Location 标头。
默认情况下,在
/etc/nginx/uwsgi_params
文件中设置了一系列设置。配置文件中的include uwsgi_params;
行是加载这些内容的。但无论出于何种原因,该方案都不是这些默认设置之一。 来修复,或者直接将其添加到
/etc/nginx/uwsgi_params
文件中。这可以通过在
include uwsgi_params;
行之后添加:到 nginx 配置中uwsgi needs to be passed the scheme (http or https) used to serve the request in order to write the correct Location header.
By default a bunch of settings are set in the
/etc/nginx/uwsgi_params
file. Theinclude uwsgi_params;
line in the config file is what load these.For whatever reason, though, the scheme is not one of these default settings. This can be fixed by adding:
to the nginx configuration after the
include uwsgi_params;
line, or by adding it to the/etc/nginx/uwsgi_params
file directly.