Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';t连接到wss://(连接建立中出错:net::ERR\u连接\u已关闭)_Javascript_Ssl_Websocket - Fatal编程技术网

Javascript Can';t连接到wss://(连接建立中出错:net::ERR\u连接\u已关闭)

Javascript Can';t连接到wss://(连接建立中出错:net::ERR\u连接\u已关闭),javascript,ssl,websocket,Javascript,Ssl,Websocket,我有带灯的VPS。我拥有Startssl.com提供的免费签名SSL证书(SSL证书工作正常) 使用http://协议,我可以连接到ws://chat.example.com:1337/一些变量,但当我将协议http://替换为https://时,我就无法连接到wss://chat.example.com:1337/some-变量 当我尝试连接到wss://时,连接建立中出现错误error:net::ERR\u connection\u CLOSED 为什么? 编辑 我有来自的资料可以更好地批评

我有带灯的VPS。我拥有Startssl.com提供的免费签名SSL证书(SSL证书工作正常)

使用
http://
协议,我可以连接到
ws://chat.example.com:1337/一些变量
,但当我将协议
http://
替换为
https://
时,我就无法连接到
wss://chat.example.com:1337/some-变量

当我尝试连接到
wss://
时,连接建立中出现错误
error:net::ERR\u connection\u CLOSED

为什么?

编辑


我有来自

的资料可以更好地批评我的答案,因为最后一个答案是错误的,我在完成挖掘之前并不打算提交,请尝试以下方法:

    // Private key and certification
    var options = {
      key: fs.readFileSync('cert/server.key'),
      cert: fs.readFileSync('cert/server.crt')
    };


    var server = https.createServer(options, function(request, response) {
    console.log((new Date()) + ' Received HTTP(S) request for ' +     request.url);
    }

cert/server.key
可以保存在
etc/apache2/myssl/server.key
?或者必须在
var/www/html/
中?没有问题。我为第一个答案道歉——我从未打算提交它。在我查看时,如果您愿意,可以将文本字段用作“记事本”。)
    // Private key and certification
    var options = {
      key: fs.readFileSync('cert/server.key'),
      cert: fs.readFileSync('cert/server.crt')
    };


    var server = https.createServer(options, function(request, response) {
    console.log((new Date()) + ' Received HTTP(S) request for ' +     request.url);
    }