我不熟悉 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 还不够,但我不确定。