WebSocket的Cookie問題(轉)


問題:我用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;
    }

以上配置需要親測。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM