需要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”;
}
}

如果有多层反向代理的话需要在每一层都加上该信息!

相关文章:

  • 2021-11-22
  • 2022-02-02
  • 2022-03-09
  • 2018-07-28
  • 2022-12-23
  • 2021-07-27
猜你喜欢
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-28
  • 2021-08-09
  • 2021-12-07
相关资源
相似解决方案