问题:我用Nginx作静态服务器,Node.js监听另外端口作WebSocket服务器,客户端创建实例时,如果origin和host不一样的话,req实例的headers中没有cookie…

 

###解决办法: Nginx配置文件搞定:

 location / {
        set $Pupgrade "";
        set $Pconnection "";
        set $Phost "";

        root $myroot;
        index index.html index.htm;
        
        if ($http_upgrade != ''){
            proxy_pass $myurl;
            set $Pupgrade $http_upgrade;
            set $Pconnection "upgrade";
            set $Phost $host;
        }
        proxy_http_version 1.1;
        proxy_set_header Upgrade $Pupgrade;
        proxy_set_header Connection $Pconnection;
        proxy_set_header Host $Phost;
    }

以上配置需要亲测。

相关文章:

  • 2021-06-22
  • 2022-12-23
  • 2021-12-06
  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2021-06-20
猜你喜欢
  • 2022-12-23
  • 2022-02-21
  • 2022-12-23
  • 2022-02-12
  • 2021-10-28
  • 2022-12-23
  • 2021-10-22
相关资源
相似解决方案