uwsgi+nginx+flask怎么配置nginx?

查看:134
本文介绍了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文件夹里没有任何文件。
请问如何修改配置?看了很多相关问题,但还是没能找到具体的解决方案,所以重新提问,谢谢。

解决方案

使用端口通信

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文件以后是否有重启?

这篇关于uwsgi+nginx+flask怎么配置nginx?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆