美文网首页运维相关
nginx 开启websocket支持

nginx 开启websocket支持

作者: 逆行的小电驴 | 来源:发表于2018-03-27 17:24 被阅读103次
  • 使用一些带有websocket通讯的网站发现普通的nginx配置满足不了
会报错socket错误
  • 编辑nginx.conf文件
在http模块增加红框中配置
    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }
  • 修改特定二级域名的server-location配置部分


    增加红框中的内容
# websocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
  • reload nginx配置


    ./nginx -s reload
  • 重新访问网站错误提示就不在了


    错误提示小时,显示websocket连接正常

相关文章

网友评论

  • kyriej2:大佬在吗,ws格式只能是ws://ip:port吗,
    不能为这种ws://127.0.0.0:80/chat.php这种吗
    逆行的小电驴:@kyriej2 可以啊,httpproxy 写成http://127.0.0.0:80/cart.php就行了

本文标题:nginx 开启websocket支持

本文链接:https://www.haomeiwen.com/subject/mluscftx.html