欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

flask_socketio + nginx + uwsgi + gevent + websocket实现稳定消息通讯 socketnginxwebsocketuwsgiflask

程序员文章站 2022-03-06 19:42:04
...
1、nginx反向代理配置:

location /socket.io {
        include uwsgi_params;

        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";

        uwsgi_pass  127.0.0.1:5000;
}

2、uwsgi ini文件配置:
[uwsgi]
socket = 127.0.0.1:5000
master = true
chdir =
wsgi-file =
processes = 1
stats = 127.0.0.1:9591
daemonize = /psd/logs/uwsgi.log
pidfile = uwsgi.pid
vacuum = true
callable = app
enable-threads = true
log-maxsize = 10000000
disable-logging = true
buffer-size=32768

http-websockets = true
gevent = 100
gevent-early-monkey-patch = true


3、flask_socketio 后台代码,网上一大堆
from flask_socketio import SocketIO, emit
...