0

I am running into an SSL error when setting up Nginx as a reverse proxy for a Node.js app. This app uses Angular to serve dynamic content and for WebSocket, we use ws. WS working properly but when attempting for wss I receive below error

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

here is configuration under /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";
    }
}

The error occurs on the client-side when attempting to connect to the WebSocket server

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

here is my frontend code

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

const CHAT_URL = "wss://cen.abcuae.com:5000";
user23316
  • 1
  • 1
  • This post doesn't show anything listening on port 5000. What is on that port? – Michael Hampton Jan 14 '21 at 07:40
  • i have edited the question , 5000 is a port for WSS that assigned – user23316 Jan 14 '21 at 10:15
  • @user23316 you need to mount [`https.Server`](https://nodejs.org/api/https.html#https_class_https_server) instance with configured TLS key and certificate to `WebSocketServer` constructor before calling new `wss` service. `wss` is a TLS-secured protocol, so you need to provide a certificate, a private key, and a properly configured server to do that. See [WebSocket-Node](https://github.com/theturtle32/WebSocket-Node/blob/39bf9037707f9cd60ce04ae6fd2203c97480c2fe/docs/WebSocketServer.md#server-config-options) documentation about this. – mforsetti Jan 14 '21 at 11:18

0 Answers0