我托管用Tornado
编写的Python WebSocket服务器。出于这个目的,我已经编写了nginx
配置,但它似乎无法正常工作。
确切的问题是,当我尝试从WS客户端建立连接时,它会失败并且服务器日志中会出现以下记录:
WARNING:tornado.access:400 GET / (127.0.0.1) 2.07ms
设置我的应用程序,以便只在根(/
)上提供WebSockets,但是根据日志判断,似乎我的请求以某种方式转换为HTTP,因此我的服务器阻止了连接。 / p>
这是我的nginx
配置文件:
server {
listen 80;
# host name to respond to
server_name ws.example.com;
location / {
# switch off logging
access_log off;
# redirect all HTTP traffic to localhost:8080
proxy_pass http://localhost:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# WebSocket support (nginx 1.4)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}