uwsgi+nginx+flask怎么配置nginx?

发布于 2022-09-05 08:24:17 字数 1010 浏览 20 评论 0

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦罢 2022-09-12 08:24:18

使用端口通信

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文