SSL 错误:如何使用 Angular 和 websocket 将 Nginx 与 Node.js 应用结合使用

SSL 错误:如何使用 Angular 和 websocket 将 Nginx 与 Node.js 应用结合使用

我在将 Nginx 设置为 Node.js 应用的反向代理时遇到了 SSL 错误。此应用使用 Angular 提供动态内容,对于 WebSocket,我们使用韋斯。WS 工作正常,但尝试 wss 时收到以下错误

WebSocket connection to 'wss://cen.abcuae.com:5000/' failed: Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR.

这是 /etc/nginx/sites-available/default 下的配置

server {


    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/cen.abcuae.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/cen.abcuae.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot




    server_name cen.abcuae.com;

    location / {
        
                proxy_pass http://0.0.0.0:8080; #whatever port your app runs on
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
                proxy_read_timeout 3600; 

}
}
server {
    listen 443;
    listen [::]:443 ssl;

     server_name cen.abcuae.com;
        ssl_certificate /etc/letsencrypt/live/cen.abcuae.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/cen.abcuae.com/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by C


    location /websocket {
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      
      proxy_set_header Host $host;
      proxy_pass https://cen.abcuae.com:5000;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }
}

客户端尝试连接 WebSocket 服务器时发生错误

WebSocket 连接‘wss://cen.abcuae.com::5000/’失败:建立连接时出错:net::ERR_SSL_PROTOCOL_ERROR

这是我的前端代码

import { WebsocketService } from "./websocket.service";

const CHAT_URL = "wss://cen.abcuae.com:5000";

相关内容