Skip to content

Latest commit

 

History

History
36 lines (24 loc) · 834 Bytes

6. LetsEncrypt with Nginx.md

File metadata and controls

36 lines (24 loc) · 834 Bytes

HTTPS with Let's Encrypt and Nginx

Install Certbot

Run sudo apt install certbot python3-certbot-nginx

Change /etc/nginx/sites-available/default before letsencrypt

Proxypass your port exposed app

server{
    server_name www.example.com;
    location / {
        proxy_pass http://www.example.com:8080;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }
}

change the port accordingly, then check syntax with sudo nginx -t

Apply letsencrypt

Run sudo certbot --nginx -d www.example.com and follow the instructions, accept redirection to allow http->https automatically

Restart nginx

sudo /etc/init.d/nginx restart

Kill nginx if failed to restart, then restart again

sudo kill -9 sudo lsof -t -i:80