SSL Configuration with Certbot
NGINX SSL Configuration
Install Certbot
-
Install Core Snap and Certbot
Install Core Snap and Certbot:
sudo snap install core; sudo snap refresh core sudo apt remove certbot sudo snap install --classic certbot sudo apt install certbot python3-certbot-nginx sudo ln -s /snap/bin/certbot /usr/bin/certbot
Configure NGINX for SSL
-
Edit NGINX Configuration
Open your NGINX site configuration file:
sudo nano /etc/nginx/sites-available/example-conf
Ensure it includes SSL settings. For example:
server { listen 80; server_name <domain_name>; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name <domain_name>; ssl_certificate /etc/letsencrypt/live/<domain_name>/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/<domain_name>/privkey.pem; # Other SSL settings ... }
-
Test NGINX Configuration
Test the NGINX configuration for errors:
sudo nginx -t
-
Reload NGINX
Apply the changes:
sudo systemctl reload nginx
Obtain an SSL Certificate
-
Run Certbot for NGINX
Obtain and install the SSL certificate:
sudo certbot --nginx -d <domain_name>
Verify Auto-Renewal
-
Check Certbot Renewal Status
Verify the status of the renewal service:
sudo systemctl status snap.certbot.renew.service
-
Dry-Run Renewal
Simulate a renewal to ensure it works:
sudo certbot renew --dry-run
Apache SSL Configuration
Install Certbot
-
Install Certbot for Apache
Install Certbot and Apache plugin:
sudo apt update sudo apt install certbot python3-certbot-apache
Configure Apache for SSL
-
Edit Apache Configuration
Open your Apache site configuration file:
sudo nano /etc/apache2/sites-available/your_domain.conf
Ensure it includes SSL settings. For example:
<VirtualHost *:80> ServerName <domain_name> Redirect permanent / https://<domain_name>/ </VirtualHost> <VirtualHost *:443> ServerName <domain_name> SSLEngine on SSLCertificateFile /etc/letsencrypt/live/<domain_name>/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/<domain_name>/privkey.pem # Other SSL settings ... </VirtualHost>
-
Test Apache Configuration
Test the Apache configuration for errors:
sudo apache2ctl configtest
-
Reload Apache
Apply the changes:
sudo systemctl reload apache2
Obtain an SSL Certificate
-
Run Certbot for Apache
Obtain and install the SSL certificate:
sudo certbot --apache
Verify Auto-Renewal
-
Check Certbot Timer Status
Verify the status of the renewal timer:
sudo systemctl status certbot.timer
-
Dry-Run Renewal
Simulate a renewal to ensure it works:
sudo certbot renew --dry-run
Summary
- NGINX: Install Certbot, configure SSL settings, obtain certificates, and verify auto-renewal.
- Apache: Install Certbot, configure SSL settings, obtain certificates, and verify auto-renewal.
Make sure to replace <domain_name>
with your actual domain and adjust file paths according to your setup.