首页 > 解决方案 > 从烧瓶中获取nginx的端口号

问题描述

我有一个 nginx 服务器在端口 5015 上侦听(在我的域上,http://foobar.com;也就是说,URL 是http://foobar.com:5015),代理到端口 8095 上的烧瓶应用程序,在我的 nginx 配置文件中使用这个:

server {

    listen 5015;
    server_name foobar.com;

    client_max_body_size 100M;
    location / {


        proxy_pass http://127.0.0.1:8095/;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_cache cache;
        proxy_cache_bypass $cookie_auth_tkt;
        proxy_no_cache $cookie_auth_tkt;
        proxy_cache_valid 30m;
        proxy_cache_key $host$scheme$proxy_host$request_uri;
    }

}

一切都很好,但我想在索引页面上的烧瓶中打印完整的 URL(包括端口号)。我已经尝试了这个答案中的所有属性,但只foobar.com打印过。

我对此很困惑。

对于request.host文档说:

发出请求的主机名,包括非标准端口。

5015(如果它使用 nginx URL)和 8095(如果它使用代理 URL)都不是标准端口(据我所知!)。

有人可以解释发生了什么,以及是否可以http://foobar.com:5015从任何Request属性中打印烧瓶?

标签: pythonnginxflaskwerkzeug

解决方案


推荐阅读