---
title: "flask_socketio + nginx + uwsgi + gevent  + websocket实现稳定消息通讯"
author: "zlr"
date: "2020-04-27T10:50:57Z"
tags: []
categories: ["Web前端"]
slug: "flask-socketio-nginx-uwsgi-gevent-websocket"
draft: false
lastmod: "2020-04-27T10:50:57Z"
id: 2513871
url: "https://zlr.iteye.com/blog/2513871"
---

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文件配置：

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
...