美文网首页nginx
Websocket:配置Nginx支持wss

Websocket:配置Nginx支持wss

作者: Anson_1f2a | 来源:发表于2021-05-06 16:31 被阅读0次

    部署过程中遇到以下异常

    Mixed Content: The page at 'https://www.xxx.com' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://www.xxx.com:8084/socket.io/?&EIO=3&transport=websocket'. This request has been blocked; this endpoint must be available over WSS.
    

    服务端:socketIO
    目标:实现wss支持
    方案:配置Nginx

    upstream websocket {
        // 内网websocket IP地址
        server 192.168.0.235:8084;
    }
    server {
            resolver 8.8.8.8;
            ssl_stapling on;
            ssl_stapling_verify on;
            listen   443 ssl;
            server_name  www.xxx.com;
            proxy_buffering off;
            ssl on;
            ssl_certificate  /etc/nginx/newtranx.com/fullchain.pem;
            ssl_certificate_key  /etc/nginx/newtranx.com/privkey.pem;
            
            // 此处省略其他配置
    
    
            location /socket.io {  
              proxy_pass http://websocket;  
              proxy_http_version 1.1;  
              proxy_set_header Upgrade $http_upgrade;  
              proxy_set_header Connection "Upgrade";  
            }
    }
    

    ps: proxy_pass http://websocket中的websocket对应upstream后面的名称
    参考:https://blog.csdn.net/chopin407/article/details/52937645

    相关文章

      网友评论

        本文标题:Websocket:配置Nginx支持wss

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