nginx + python + websockets [英] nginx + python + websockets
问题描述
如何配置nginx(最新版本,他们说它支持websocket)来支持WebSockets.
How can I configure nginx (latest version, they say it supports websockets) to support WebSockets.
以及如何使用python运行websockets连接.
And how can I use python to run websockets connection.
我想要的是
- 客户端使用JavaScript创建WebSocket;
- websocket服务器脚本在python上运行;
- 和所有后端的nginx.
有人可以帮助我吗?
推荐答案
I took a quick look at the relevant changeset to Nginx, and it looks like all you need to do to start handling websocket requests is to set up a proxy in your nginx config. So for example:
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上的本地连接.
This little configuration snippet will proxy incoming websocket traffic to your Python application server, assumed in the example to be listening for local connections on port 5000.
希望这会有所帮助.
这篇关于nginx + python + websockets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!