简体   繁体   English

带有 NGINX proxy_pass 的 Flask

[英]Flask with NGINX proxy_pass

I have a python flask server running on localhost:5000我有一个在 localhost:5000 上运行的 python Flask 服务器

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

Problem is, flask's url_for links will bypass any configuration, for example, I may have this button :问题是,flask 的 url_for 链接会绕过任何配置,例如,我可能有这个按钮:

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

Which will them route the browser to www.example.com/rest , which maps to nothing.他们会将浏览器路由到www.example.com/rest ,而后者什么也没有。

How can I fix this?我怎样才能解决这个问题? From my understanding just changing nxing conf isn't enough, I also need to change something in Flask根据我的理解,仅仅改变 nxing conf 是不够的,我还需要在 Flask 中改变一些东西

My NGINX conf is as follows :我的 NGINX 配置如下:

location /deploy/ {

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

}

Try this尝试这个

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
      ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM