我有一个 Flask 应用程序在gunicorn上运行http://127.0.0.1:4000
:
gunicorn -b 127.0.0.1:4000 webapp:app
现在我想使用nginx作为反向代理和转发http://myserver.com/webapp
to http://127.0.0.1:4000
以某种方式,每个http://myserver.com/webapp/subpath
去http://127.0.0.1:4000/subpath
.
不使用子路径时,代理/重定向可以很好地工作:
upstream app {
server 127.0.0.1:4000 fail_timeout=0;
}
server {
listen 80 default;
client_max_body_size 4G;
server_name _;
location / {
proxy_pass http://app;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
}
我该如何设置
location /webapp {
#go to my gunicorn app, translate URLs nicely
}
Flask 开发人员的这个技巧不起作用:http://flask.pocoo.org/snippets/35/ http://flask.pocoo.org/snippets/35/罢工>
已解决:片段http://flask.pocoo.org/snippets/35/ http://flask.pocoo.org/snippets/35/作品!我的模板中有一些绝对 URL(例如/task/delete
)并且必须将一切更改为url_for()
.
愚蠢...但现在它按预期工作,我的应用程序已打开'http://myserver.com/subpath http://myserver.com/subpath'
我解决了我的问题:片段http://flask.pocoo.org/snippets/35/ http://flask.pocoo.org/snippets/35/确实有效,我太愚蠢了,在我的模板中包含绝对 URL。我把它改为url_for()
现在它就像魅力一样发挥作用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)