Step 1: Nginx Config File (nginx.conf)

server {
    listen 80;
    listen [::]:80;

    server_name at10346.chickenkiller.com www.at10346.chickenkiller.com;
    server_tokens off;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        return 301 https://at10346.chickenkiller.com$request_uri;
    }
}

server {
    listen 443 default_server ssl http2;
    listen [::]:443 ssl http2;

    server_name example.org;

    ssl_certificate /etc/nginx/ssl/live/at10346.chickenkiller.com/fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/live/at10346.chickenkiller.com/privkey.pem;

    location / {
        proxy_pass <http://localhost:4040>;
    }
}

Step 2: Auto Renew SSL using Shell Script (cron_ssl_renew.sh)

#!/bin/bash

/usr/local/bin/docker-compose -f $HOME/docker_nginx/docker-compose.yml run --rm certbot renew && /usr/local/bin/docker-compose -f $HOME/docker_nginx/docker-compose.yml restart webserver

Step 3: Docker Compose File (docker-compose.yml)

version: '3'

services:
  webserver:
    image: nginx:latest
    ports:
      - 80:80
      - 443:443
    restart: always
    volumes:
      - ./nginx/conf/:/etc/nginx/conf.d/:ro
      - ./certbot/www:/var/www/certbot/:ro
      - ./certbot/conf/:/etc/nginx/ssl/:ro
  certbot:
    image: certbot/certbot:latest
    volumes:
      - ./certbot/www/:/var/www/certbot/:rw
      - ./certbot/conf/:/etc/letsencrypt/:rw
networks:
  default:
    external:
      name: miner_magnews

Step 4: Setup Steps

  1. Get a free subdomain name from http://freedns.afraid.org/subdomain/edit.php?data_id=20945780 and set it to your host IP.

  2. Follow the instructions at https://certbot.eff.org/instructions to install Certbot for free SSL certificates.

  3. Create a folder for the docker-compose.yml file and copy the contents from the example above.

  4. Create a folder for the Nginx config with your free domain and copy the Nginx config file shown above.

  5. Run Docker Compose to start Nginx: docker-compose up -d.

  6. Obtain the SSL certificate for your domain using Certbot:

    docker-compose run --rm certbot certonly --webroot --webroot-path /var/www/certbot/ -d at10346.chickenkiller.com
    
    
  7. Restart Nginx to load the SSL certificate: docker-compose restart webserver.

  8. Create a shell script for auto-renewing the SSL certificate. Name it cron_ssl_renew.sh and paste the content from Step 2.

  9. Grant execute permissions to the shell script:

    chmod +x cron_ssl_renew.sh
    
    
  10. Set up a cron job to run the shell script for auto-renewal. Add the following line to your crontab:

    0 0 1 * * $HOME/docker_nginx/cron_ssl_renew.sh 2>&1 | tee $HOME/docker_nginx/log.txt
    
    

That's it! Your Node.js app should now be running with SSL enabled using Nginx and Certbot for auto-renewal.