不需要的 HTTPS ->使用 nginx 进行 HTTP 重定向 + uwsgi +烧瓶应用程序

发布于 2024-12-03 10:57:29 字数 829 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妳是的陽光 2024-12-10 10:57:29

uwsgi 需要传递用于服务请求的方案(http 或 https),以便写入正确的 Location 标头。

默认情况下,在 /etc/nginx/uwsgi_params 文件中设置了一系列设置。配置文件中的 include uwsgi_params; 行是加载这些内容的。

但无论出于何种原因,该方案都不是这些默认设置之一。 来修复,或者直接将其添加到 /etc/nginx/uwsgi_params 文件中。

uwsgi_param UWSGI_SCHEME $scheme;

这可以通过在 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. The include 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:

uwsgi_param UWSGI_SCHEME $scheme;

to the nginx configuration after the include uwsgi_params; line, or by adding it to the /etc/nginx/uwsgi_params file directly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文