【nginx】ws nginx如何配置ssl连通 node

nginx配置

server {

listen 443 ssl;

server_name loran.data168.cn;

ssl_certificate /usr/local/www/loran/ssl/3752226_loran.data168.cn.pem;

ssl_certificate_key /usr/local/www/loran/ssl/3752226_loran.data168.cn.key;

ssl_session_timeout 5m;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;

ssl_prefer_server_ciphers on;

location ~ /wss/ {

proxy_pass http://localhost:9003; #通过配置端口指向部署websocker的项目

proxy_http_version 1.1;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection "Upgrade";

proxy_set_header X-real-ip $remote_addr;

proxy_set_header X-Forwarded-For $remote_addr;

}

}

## 前端js配置

const WebSocket = require('ws');

const ws = new WebSocket('wss://loran.data168.cn:9003/wspath');

ws.on('open', function open() {

ws.send('something');

});

ws.on('message', function incoming(data) {

console.log(data);

});

后端node配置

const WebSocket = require('ws');

const wss = new WebSocket.Server({ port: 9003});

wss.on('connection', function connection(ws) {

console.log(1111)

ws.on('message', function incoming(message) {

console.log('received: %s', message);

});

ws.send('something');

});

报错
【nginx】ws  nginx如何配置ssl连通   node

有没有大牛愿意解释一下,感激不尽。

回答

websocket 应该连的是 nginx 的 443 端口,不是 nginx 代理的 9003

以上是 【nginx】ws nginx如何配置ssl连通 node 的全部内容, 来源链接: utcz.com/a/85044.html

回到顶部