flask-socketio + gunicorn + nginx通过unix socket文件[Errno -2]

时间:2015-04-03 10:39:40

标签: unix nginx flask gunicorn flask-socketio

我在Flask上创建网站。与服务器的所有通信都通过WebSockets进行。 当我使用带有TCP / IP的gunicorn时:

gunicorn --worker-class socketio.sgunicorn.GeventSocketIOWorker chat:app --bind=127.0.0.1:8800

一切正常。但是当我使用Unix套接字文件时:

gunicorn --worker-class socketio.sgunicorn.GeventSocketIOWorker chat:app -b unix:///var/sockets/gunicorn.sock

我在日志中遇到错误:

[root@localhost legalize]# gunicorn --worker-class socketio.sgunicorn.GeventSocketIOWorker chat:app -b unix:///var/sockets/gunicorn.sock
2015-04-03 13:32:26 [25392] [INFO] Starting gunicorn 18.0
2015-04-03 13:32:26 [25392] [INFO] Listening at: unix:/var/sockets/gunicorn.sock (25392)
2015-04-03 13:32:26 [25392] [INFO] Using worker: socketio.sgunicorn.GeventSocketIOWorker
2015-04-03 13:32:26 [25397] [INFO] Booting worker with pid: 25397
FAILED to start flash policy server: [Errno -2] Name or service not known: ('/', 10843)
FAILED to start flash policy server: [Errno -2] Name or service not known: ('/', 10843)
FAILED to start flash policy server: [Errno -2] Name or service not known: ('/', 10843)

我如何解决此错误?

1 个答案:

答案 0 :(得分:1)

项目gevent-socketio(处理Socket.IO协议的Flask-SocketIO的依赖项)启动用于Flash传输的辅助Web服务器。此服务器在与主服务器相同的主机上侦听,但在端口10843上侦听。当主服务器侦听unix套接字时,显然该逻辑失败。

您需要提供Flash支持吗?如果没有,我建议您通过将环境变量POLICY_SERVER设置为非空值来完全禁用它。以下是禁用策略服务器的逻辑,以防您好奇:https://github.com/abourget/gevent-socketio/blob/668d11edbd62052cde1583be1e1d0512c930f16d/socketio/sgunicorn.py#L43-L47