我有这个conf:
location /dev/api {
proxy_pass http://127.0.0.1:8081;
}
location /api {
proxy_pass http://127.0.0.1:8081;
}
/ dev / api和/ api应该点击相同的Flask API后端,当/ dev / api命中时,后端将其选为/ dev / api,但是,因为API绑定到/ api,它返回404我知道我可以在后端添加另一个API资源来监视/ dev / api,但它有点重复。
class HelloWorld(restful.Resource):
def get(self, share_id):
return {'hello': 'worlds'}
api.add_resource(HelloWorld, '/api/share/<int:share_id>', '/dev/api/share/<int:share_id>')
有没有办法让nginx以某种方式将/ dev / api指向/ api,而后端将其作为/ api而不是/ dev / api?
谢谢!
答案 0 :(得分:0)
我相信您正在寻找的是nginx's equivalent of ProxyPassReverse:
location /dev/api {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8081;
}
location /api {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8081;
}
另外,您可能需要查看flask's notes on the subject
注意:未经测试。