2014-12-08 41 views
2

我正在使用Nginx + uWSGI + Flask構建Web服務API。如何通過瓶子處理web api

我按照http://flask.pocoo.org/docs/0.10/deploying/uwsgi/如下

在Nginx的,我想瓶處理所有要求appapi和其他nginx的處理。

ex。
http://www.example.com/appapi/query?name=123將由燒瓶處理
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,沒有找到。
在此先感謝!在Nginx的配置

@app.route('/query', methods=['GET']) 
def query(): 
    print 'query()' 

然後:

回答

2

你可以做到這一點

location /appapi/ { 
    include uwsgi_params; 
    uwsgi_pass 127.0.0.1:3301; 
} 
+0

似乎作品,謝謝,我有更多的問題,爲什麼文件(HTTP://flask.pocoo .org/docs/0.10/deployloying/uwsgi /)使用uwsgi_modifier1和uwsgi_param以及它爲什麼不起作用? – 2014-12-08 03:29:28

+0

'uwsgi_modifier1'已棄用。 'uwsgi_param'傳遞腳本名稱,但是使用基於'/' – nathancahill 2014-12-08 17:09:50

+0

的路由更簡單,是的,我使用/ routes,它工作正常,然後我只想將api路由到flask並且其他人使用nginx處理,但是我遇到了問題在帖子中提出。 – 2014-12-09 04:55:32