【发布时间】:2021-07-01 00:21:37
【问题描述】:
我正在尝试在带有 nginx 和 gunicorn 的 VPS 上部署 Flask 应用程序。
location /app {
root /var/www/mydomain.com/html/flask_app;
proxy_pass http://127.0.0.1:8000/;
proxy_redirect http://$http_host/ https://$http_host/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
小米烧瓶应用有这样的路由:
@app.route('/streaming_events', methods=['GET', 'POST'])
@app.route('/api/streaming_events', methods=['GET'])
def streaming_events():
if request.method == 'GET':
streaming_events = api.get_streaming_events()
if request.path == '/api/streaming_events':
response = jsonify(streaming_events)
response.headers.add('Access-Control-Allow-Origin', '*')
return response
return render_template('index.html', streaming_events=streaming_events)
elif request.method == 'POST':
api.create_streaming_event(request.get_json())
return jsonify({})
mydomain.com/app/streaming_events 工作正常,但是 mydomain.com/app/api/streaming_events 给我“未找到”。 它在我的本地机器上运行良好。
【问题讨论】:
-
你在前缀路由中运行了flask吗?
-
尝试使用:
location /app/,尾随/。 -
@RichardSmith 我试过了,没用。
-
@ThanhNguyenVan 是的,但没用。