热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

websocket请求nginx监听的端口,出现WebSocketopeninghandshakewascanceled

nginx版本是1.10.1

nginx版本是1.10.1



nginx配置tcp转发:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
tcp{

    upstream ge_ssl {

            server 127.0.0.1:1234;

    }



    map $http_upgrade $connection_upgrade{

            default upgrade;

            ''      close;

    }

   

    server{

            listen 9988;

            ssl on;

            ssl_certificate /etc/le/l/abc.com/fullchain.pem;

            ssl_certificate_key /etc/le/l/abc.com/privkey.pem;

            ssl_session_timeout  5m;

            ssl_protocols  SSLv2 SSLv3  TLSv1.1 TLSv1.2;

            ssl_ciphers  HIGH:!aNULL:!MD5;

            ssl_prefer_server_ciphers   on;

            location / {

                    proxy_pass http://ge_ssl;

                    proxy_http_version 1.1;

                    #proxy_ssl_session_reuse off;

                    proxy_set_header Upgrade $http_upgrade;

                    proxy_set_header Connection "upgrade";

            }

    }

   

}

nginx监听端口:443,80,9988



1
2
3
4
5
    443:ssl证书



    80:rewrite 跳转443

   

    9988:该端口为了应对网页的websocket请求,然后将请求转发给1234端口

浏览器:FireFox,Chrome

网页代码:

1
2
3
4
5
6
7
8
9
10
11
12
    var ws = new WebSocket('ws://129.136.145.58:9988');



    在FireFox上面,可以通过,Chrome上面,会出错,错误如下:



    Mixed Content: The page at 'https://www.abc.com/me' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://129.136.145.58:9988/'. This request has been blocked; this endpoint must be available over WSS.

    Uncaught SecurityError: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.



所以网页代码改用为var ws = new WebSocket('wss://129.136.145.58:9988');



这下FireFox和Chrome一起失败了...错误如下:

           

WebSocket connection to 'wss://129.136.145.58:9988/' failed: WebSocket opening handshake was canceled

查了好多资料都不知道为啥,求大神指点一二,感激不尽。。。


   



推荐阅读
author-avatar
手机用户2502851955
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有