【发布时间】:2014-12-08 03:04:52
【问题描述】:
我正在使用 Nginx+uWSGI+Flask 来构建 Web 服务 API。
我关注http://flask.pocoo.org/docs/0.10/deploying/uwsgi/如下
在 Nginx 中,我希望 Flask 处理所有请求 appapi,而其他请求由 nginx 处理。
ex.
http://www.example.com/appapi/query?name=123 将由 flask 处理
http://www.example.com/ 将由 nginx 处理。
我添加下面的配置让烧瓶处理。
location = /appapi { rewrite ^ /appapi /; }
location /appapi { try_files $uri @appapi ; }
location @appapi {
include uwsgi_params;
uwsgi_param SCRIPT_NAME /appapi;
uwsgi_modifier1 30;
uwsgi_pass 127.0.0.1:3301;
}
uWSGI 有监听 3301 端口,会在 Flask 应用代码中加载烧瓶应用。我已经为 appapi 定义了路由
@app.route('/appapi/query', methods=['GET'])
def query():
print 'query()'
但是我发现查询函数没有被调用,并且在日志中。它返回 404,未找到。
提前致谢!
【问题讨论】: