How to create websocket secure by using NodeJS


Method 1:

In this article: How to run a https website with Nodejs, express and socket.io

Method 2: use NGINX

file .conf

upstream myapp1{
	server 127.0.0.1:33333;
}

server {
    listen 443;
    server_name ws.tutorialspots.xyz;

    ssl on;
ssl_certificate /etc/letsencrypt/live/ws.tutorialspots.xyz/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/ws.tutorialspots.xyz/privkey.pem; # managed by Certbot
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    location / {
            access_log off;
            
			proxy_pass http://myapp1;
            proxy_redirect off;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_read_timeout 86400;

            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
    }

}

Now, you can use websocket to create websocket secure:
Read more:
Example chat application using Nodejs + Socket.io
Example chat application using Nodejs + ws
Example chat application using Nodejs + Websocket

Related Post

, , ,

No comments yet.

Leave a Reply