我如何配置nginx(最新版本,他们说它支持websockets)来支持WebSockets。
我如何使用 python 来运行 websockets 连接。
这就是我想要的:
- 客户端使用 JavaScript 创建 WebSocket;
- websocket服务器脚本在python上运行;
- nginx 位于所有这一切的后端。
有谁能够帮助我?
我快速浏览了相关内容变更集 http://trac.nginx.org/nginx/changeset/5073/nginx对于 Nginx,看起来开始处理 websocket 请求所需要做的就是在 nginx 配置中设置代理。例如:
upstream pythonserver {
server localhost:5000;
}
server {
// normal server config stuff...
location /some/uri/here {
// Minimum required settings to proxy websocket connections
proxy_pass http://pythonserver;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
// Other settings for this location
}
}
这个小配置片段会将传入的 websocket 流量代理到您的 Python 应用程序服务器,在示例中假设正在侦听端口 5000 上的本地连接。
希望这可以帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)