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');
});

报错
image.png

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

待解决 悬赏分:50 - 离问题结束还有 460天23小时28分13秒
反对 0举报 0 收藏 0

我来回答

回答1