Install Nginx with Let’s Encrypt Ubuntu 24.04

sudo apt install certbot python3-certbot-nginx -y
sudo nano /etc/nginx/sites-available/example.com
server {
        listen 80;
        listen [::]:80;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name example.com;

        location / {
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

                proxy_pass http://127.0.0.1:8080;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";

               #try_files $uri $uri/ =404;
        }

        #location ~ /\.ht {
        #       deny all;
        #}
}
sudo ln -fs /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com
sudo certbot --nginx -d example.com
sudo systemctl status certbot.timer

Check if certbot autorenew is setup properly

sudo certbot renew --dry-run
sudo ufw allow 'Nginx Full'

To setup DNS based SSL one-time only

sudo certbot --manual --preferred-challenges dns certonly -d example.com

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *