問題:我用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; }
以上配置需要親測。