【问题标题】:Using gunicorn raises KeyError wsgi.websocket使用 gunicorn 引发 KeyError wsgi.websocket
【发布时间】:2015-11-27 22:31:21
【问题描述】:

我不熟悉 gunicorn 和系统管理,并试图将其部署在服务器上。

进程的运行非常简单,我是使用命令完成的

gunicorn -c gunicorn_config.py --bind 127.0.0.1:8000 -k gevent_wsgi --daemon wsgi:app

gunicorn_config.py

workers = 2
worker_class = 'socketio.sgunicorn.GeventSocketIOWorker'
transports = ['websockets', 'xhr-polling']
bind = '127.0.0.1:8000'
pidfile = '/tmp/gunicorn.pid'
debug = False
loglevel = 'info'
errorlog = '/tmp/gunicorn.log'
resource = "socket.io"

wsgi.py

import os.path as op
import werkzeug.serving
import gevent.monkey
gevent.monkey.patch_all()

from bakery import create_app, init_app

app = create_app(app_name='bakery')
app.config.from_object('config')
app.config.from_pyfile(op.join(op.realpath(op.dirname(__name__)), 'local.cfg'))
init_app(app)
from socketio.server import SocketIOServer
SocketIOServer(('0.0.0.0', 5000), app,
    resource="socket.io", policy_server=True,
    transports=['websocket', 'xhr-polling'],
    ).serve_forever()

nginx 设置为在 location 中使用

proxy_pass http://localhost:8000

gunicorn 成功运行,但在对应用程序进行多次操作后,它会因 KeyError 'wsgi.websocket' 而崩溃。似乎传输 websocket 还不够,但我不确定。

【问题讨论】:

    标签: nginx flask wsgi gevent gunicorn


    【解决方案1】:

    我遇到了这个问题; nginx 需要配置为代理 web 套接字:http://nginx.org/en/docs/http/websocket.html

    【讨论】:

      【解决方案2】:

      原因可能是使用多个 gunicorn worker 时出现问题,请参阅:https://github.com/abourget/gevent-socketio/issues/132

      尝试将工作人员的数量设置为 1,看看是否确实如此。

      【讨论】:

        猜你喜欢
        • 2012-04-07
        • 2011-02-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-17
        • 2020-08-12
        • 1970-01-01
        相关资源
        最近更新 更多