【问题标题】:uWSGI + Gevent not receiving requests from NginxuWSGI + Gevent 没有收到来自 Nginx 的请求
【发布时间】:2020-04-16 20:12:53
【问题描述】:

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

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] ***

此时,尽管我尝试访问该页面(我得到错误 502 Bad Gateway),但程序没有进一步输出。

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

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

连接服务

[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;

}

}

【问题讨论】:

    标签: python-3.x nginx uwsgi gevent flask-socketio


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2015-12-29
      • 1970-01-01
      • 2019-08-01
      • 2016-02-15
      • 2016-03-05
      • 2013-11-24
      • 1970-01-01
      • 2014-08-03
      • 2020-09-30
      相关资源
      最近更新 更多