Skip to content

Add SSL

Video Lecture

Add SSL Add SSL

Description

Let's make http://socketio-example.your-domain.tld have an SSL certificate and redirect all HTTP traffic to HTTPS

We can get free certificates from CertBot

Before we start, we should add the server_name setting to our Nginx conf that we created for our socketio-example website.

cd /etc/nginx/sites-enabled/
nano socketio-example.conf

Add the highlighted line, and change YOUR-DOMAIN-NAME to be your domain name.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
server {
    listen 80;
    listen [::]:80;
    server_name  YOUR-DOMAIN-NAME;

    location /socket.io/ {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_pass "http://localhost:3000/socket.io/";
    }

    location / {
        proxy_pass           http://127.0.0.1:3000/;
    }
}

Now we can install Certbot and enable the command.

sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot

And now run it.

sudo certbot --nginx

Note

If your domain name hasn't fully propagated across the internet yet, then CertBot will not be able to validate your request with your IP and you will need to try again an hour or so later.

Now visit https://socketio-example.your-domain.tld

or visit mine to see a working example

https://socketio-example.sbcode.net/