【问题标题】:Flask with NGINX proxy_pass带有 NGINX proxy_pass 的烧瓶
【发布时间】:2020-02-22 07:47:06
【问题描述】:

我有一个在 localhost:5000 上运行的 python 烧瓶服务器

我希望 NGINX 将 www.example.com/app/rest 转发到 localhost:5000/rest

问题是,flask 的 url_for 链接会绕过任何配置,比如我可能有这个按钮:

<a href="/rest">Rest</a>

他们会将浏览器路由到www.example.com/rest,它什么都没有。

我该如何解决这个问题?据我了解,仅更改 nxing conf 是不够的,我还需要更改 Flask 中的某些内容

我的 NGINX 配置如下:

location /deploy/ {

      proxy_pass http://localhost:5000/;
      proxy_set_header Host $host;

}

【问题讨论】:

    标签: python nginx flask


    【解决方案1】:

    试试这个

    location /app/rest/ { # the trailing slash at the end is important
    
          proxy_pass http://localhost:5000/rest;
          proxy_set_header Host $host;
    
    }
    
    location /deploy/ {
    
          proxy_pass http://localhost:5000/;
          proxy_set_header Host $host;
    
    }
    ...
    location / { # always be placed at the end
          ...
    }
    

    【讨论】:

      猜你喜欢
      • 2018-10-25
      • 2016-03-20
      • 1970-01-01
      • 1970-01-01
      • 2012-11-28
      • 1970-01-01
      • 1970-01-01
      • 2012-04-18
      • 1970-01-01
      相关资源
      最近更新 更多