需要nginx作为websocket的反向代理,没有nginx反向代理时候没有问题,通过nginx反向代理后会报400错误,查后台调试信息:
tornado.general – DEBUG – Can “Upgrade” only to “WebSocket”.
通过分析原来是需要nginx做如下配置:
upstream wsbackend { server 127.0.0.1:10003; } server { listen 3000; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; # location / { # root html; # index index.html index.htm; # } location / { proxy_pass http://wsbackend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection “upgrade”; } }
如果有多层反向代理的话需要在每一层都加上该信息!