这是我第一次使用NGINx和uwsgi。我已经阅读了几个教程,主要是这个教程(https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-ubuntu-14-04),但是,当我在我的烧瓶应用程序中定义了动态URL和多个应用程序路径时,它并没有特别有用。为简单起见,这里是我的app.py(flask),以及我的ngingx配置:
app.py(StackExchange的简化版)
from flask import Flask
application = Flask(__name__)
#works!
@application.route("/")
def hello():
return "<h1 style='color:blue'>Hello There!</h1>"
#DOESN'T WORK
@application.route("/<userId>")
def hello_user():
return "<h1 style='color:blue'>Hello some user!</h1>"
if __name__ == "__main__":
application.run(host='0.0.0.0')
nginx配置:
server {
listen 9090;
server_name myapp.new;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/user1/NGINxApp/app.sock;
}
}
如何在此处允许动态网址(使用变量规则)?
答案 0 :(得分:0)
我能够在这里找到解决方案:
http://flask.pocoo.org/docs/0.10/deploying/uwsgi/
我稍微更改了nginx配置,现在它可以工作:
location / { try_files $uri @yourapplication; }
location @yourapplication {
include uwsgi_params;
uwsgi_pass unix:/home/user1/NGINxApp/app.sock;
}