问题:我用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; }
以上配置需要亲测。