【发布时间】:2020-01-24 09:24:43
【问题描述】:
当我尝试与我的服务器建立wss 连接时出现此错误:
到“wss://mydomain:3000/”的 WebSocket 连接失败:错误 连接建立:net::ERR_CONNECTION_CLOSED
我目前有一个 apache2 虚拟主机配置设置来监听端口 443 和 80 上的请求:
<VirtualHost *:80>
ServerName otherdomainname.co.uk
ServerAlias www.otherdomainname.co.uk
RewriteEngine On
RewriteRule ^/(.*)$ /app/$1 [l,PT]
JkMount /* worker2
</VirtualHost>
<VirtualHost _default_:443>
ServerName otherdomainname.co.uk
ServerAlias www.otherdomainname.co.uk
RewriteEngine On
RewriteRule ^/(.*)$ /app/$1 [l,PT]
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
<Location />
SSLRequireSSL On
SSLVerifyClient optional
SSLVerifyDepth 1
SSLOptions +StdEnvVars +StrictRequire
</Location>
JkMount /* worker2
</VirtualHost>
如您所见,它使用 JkMount 将请求传递给 Tomcat,后者在 HTTP 和 HTTPS 上都正确地为网页提供服务。
当我在端口 80 上使用 HTTP 协议访问该站点时,可以使用 ws 协议建立 WebSocket 连接。
当我在端口 443 上使用 HTTPS 协议访问站点时,站点服务正常,但没有使用 wss 建立 WebSocket 连接。
我正在使用“ws”node.js 模块来提供 WebSocket 服务器:
var WebSocketServer = require('ws').Server
, wss = new WebSocketServer({ port: 3000 }),
fs = require('fs');
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
console.log('received: %s', message);
ws.send(message);
ws.send('something');
});
为什么我无法通过https 使用wss 协议成功连接到WebSocket 服务器?
【问题讨论】:
标签: node.js apache https websocket wss