'NGINX and nodeJs works with http but not https

I have this config for NGINX:

server {
  listen       80;
  listen       443 ssl;
  server_name  rahim27.fr;

  ssl_certificate  /etc/letsencrypt/live/rahim27.fr/cert.pem;
  ssl_certificate_key /etc/letsencrypt/live/rahim27.fr/privkey.pem;

  error_log logs/error.log warn;

  location / {
    proxy_pass http://localhost:8080;
    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;
  }
}

And this basic NodeJS server :

const http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200);
  res.end("hello world\n");
}).listen(8080);

When I go to http://rahim27.fr/, I get my hello world but if I try https://rahim27.fr/ I get ERR_CONNECTION_RESET, with curl it gives me curl: (7) Failed to connect to rahim27.fr port 443: No route to host from Linux (the VM) and curl: (35) schannel: failed to receive handshake, SSL/TLS connection failed from Windows.

The server is in a cloud VM, I opened up all ports in the cloud dashboard and in the VM itself.

The SSL certificate was generated by certbot automatically.

What I want :

  1. Have https://rahim27.fr/ return a hello world
  2. After serving both http and https correctly, I would also like to redirect all http traffic to https

What I tried :

  1. Looking on stackoverflow
  2. Opening up all ports on the VM (at least while I'm on the development phase)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source