带有NGINX proxy_pass的烧瓶

时间:2020-02-21 19:52:01

标签: python nginx flask

我有一个在本地主机上运行的python flask服务器:5000

我希望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 conf如下:

location /deploy/ {

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

}

1 个答案:

答案 0 :(得分: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
      ...
}