uWSGI + Gevent 没有收到来自 Nginx 的请求

uWSGI + Gevent not receiving requests from Nginx

我是 uWSGI/gevent 的新手,我有一个 Python Flask 服务器,Flask-SocketIo 位于 Nginx 后面,每当 gevent 的循环引擎 运行s 时,服务器似乎会冻结.示例输出如下所示:

compiled with version: 7.5.0 on 15 April 2020 12:57:22
os: Linux-4.15.0-96-generic #97-Ubuntu SMP Wed Apr 1 03:25:46 UTC 2020
nodename: xxxxxxxxxx
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /home/admin/myapplication
detected binary path: /home/admin/myapplication/venv/bin/uwsgi
your processes number limit is 3838
your memory page size is 4096 bytes
detected max file descriptor number: 1024
- async cores set to 1000 - fd table size: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address connect.sock fd 3
Python version: 3.6.9 (default, Nov  7 2019, 10:44:02)  [GCC 8.3.0]
Python main interpreter initialized at 0x55701b9d6e40
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 21036928 bytes (20543 KB) for 1000 cores
*** Operational MODE: async ***
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x55701b9d6e40 pid: 2692 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 2692)
spawned uWSGI worker 1 (pid: 2710, cores: 1000)
*** running gevent loop engine [addr:0x557019f92410] ***

此时,尽管我尝试访问该页面(我收到 Error 502 Bad Gateway),但程序没有产生进一步的输出。

该应用程序是通过服务文件 运行 运行的,当我直接从命令行 运行 该应用程序时,它似乎工作正常。任何人都可以识别我的代码中的问题吗? (提前致谢)

这是我的服务文件的副本:

connect.service

[Unit]
Description= xxxxxxxxxxxx
After=network.target

[Service]
User=admin
Group=www-data
WorkingDirectory=/home/admin/myapplication
Environment="PATH=/home/admin/myapplication/venv/bin"
ExecStart=/home/admin/myapplication/venv/bin/uwsgi --ini service_files/connect.ini

[Install]
WantedBy=multi-user.target

connect.ini

[uwsgi]
module = wsgi:app

master = true
gevent = 1000
http-websockets = true

socket = connect.sock
chmod-socket = 660
vacuum = true
logto = /home/admin/myapplication/service_files/logs/uwsgi/%n.log

die-on-term = true

Nginx 站点

server {

listen 80;

server_name subdomain.domain.com;

return 301 https://$server_name$request_uri;

}

server {

listen 443 ssl;

ssl_certificate /home/admin/myapplication/service_files/connect.crt;

ssl_certificate_key /home/admin/myapplication/service_files/connect.key;

server_name subdomain.domain.com;

location / {

include uwsgi_params;
uwsgi_pass unix:///home/admin/myapplication/connect.sock;

}

location /socket.io/ {

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
include uwsgi_params;
uwsgi_pass unix:///home/admin/myapplication/connect.sock;

}

}

问题是由于权限错误(在使用命令 sudo tail -30 /var/log/nginx/error.log 进行更多挖掘后)

转到 connect.ini 文件并将 chmod-socket = 660 更改为 chmod-socket = 666 解决了问题。