【发布时间】:2021-08-06 01:47:51
【问题描述】:
我正在尝试使用 wscat 和浏览器通过自签名证书连接到 wss(proxy),但它给了我错误。
- https 使用证书 cert.pem 在 8443 上运行
- 代理在 8080 上运行,具有安全真值
我已尝试确保我的安全服务器正常运行。
- 我可以访问 https://localhost:8443 并收到“来自安全世界的你好”
- 我可以使用 wscat
wscat -c wss://localhost:8443 --ca cert.pem连接到 wss://localhost:8443 并且可以正常工作
我得到的错误:
- 我无法从浏览器访问代理 https://localhost:8080。我收到此站点无法提供安全连接和 500 状态代码
- 我无法使用
wscat -c wss://localhost:8080 --ca cert.pem连接到 wss://localhost:8080 我得到error: write EPROTO 140266887743360:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:
我认为问题在于我的代理服务器无法获取 cert.pem 并将其传递给 https 服务器。我到处寻找,但找不到如何使用自签名证书连接到 wss(proxy)。我无法抑制
/服务器
const app = express()
app.use('/', function (req, res) {
res.writeHead(200);
res.end("hello from a secure world\n");
})
export const server = https.createServer({
cert: fs.readFileSync(path.resolve(__dirname, 'cert.pem'), 'utf-8'),
ca: fs.readFileSync(path.resolve(__dirname, 'cert.pem'), 'utf-8'),
key: fs.readFileSync(path.resolve(__dirname, 'server.key'), 'utf-8')
}, app)
const wss = new WebSocket.Server({ server });
wss.on('connection', function connection(ws) {
console.log("connected");
ws.on('message', function incoming(message) {
console.log('received: %s', message);
ws.send('hello from server!, the time is: ' + timestamp());
});
});
/代理
const wsProxy = createProxyMiddleware('/', {
target: `https://localhost:8443`,
changeOrigin: true,
secure: true,
ws: true,
ssl: {
cert: fs.readFileSync(path.resolve(__dirname, 'cert.pem')),
}
});
const app = express();
app.use(wsProxy);
const proxy = app.listen(8080)
proxy.on('upgrade', wsProxy.upgrade); // <-- subscribe to http 'upgrade'
【问题讨论】:
标签: ssl websocket proxy self-signed-certificate