uwsgi+nginx+flask怎么配置nginx?

在学习flask部署一节时,需要用到uwsgi和nginx。根据官方文档安装完uwsgi和nginx后,做了一个测试。测试代码如下:
test.py

def application(env, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])
    return "<h1>Hello, World!</h1>".encode('utf-8')

运行uwsgi --http :9090 --wsgi-file test.py后可以正常浏览http://localhost:9090.
配置nginx:
example

server {
    listen 80;
    location / {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:9090;
    }
}

启动nginx和uwsgi后浏览http://localhost后启动的是nginx默认页面,而带9090端口则正常显示hello world。
我试过直接修改sites-enabled/default结果也一样,conf.d文件夹里没有任何文件。
请问如何修改配置?看了很多相关问题,但还是没能找到具体的解决方案,所以重新提问,谢谢。

阅读 2.7k
1 个回答

使用端口通信

location / {
    include uwsgi_params;
    uwsgi_pass 127.0.0.1:3031;
    root  html;
    index  index.html index.htm;
}

使用socket文件通信

server{
    listen  80;
    server_name  localhost;
    location /{
        include uwsgi_params;
        uwsgi_pass  unix://path/to/uwsgi.sock
    }
}

你配置完nginx的conf文件以后是否有重启?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题