SSL Setup¶
Configure SSL/TLS certificates for secure HTTPS access.
Let's Encrypt (Recommended)¶
Install Certbot¶
Obtain Certificate¶
Stop any service on port 80:
# Stop nginx if running
docker compose stop nginx
# Obtain certificate
sudo certbot certonly --standalone -d your-domain.com
# Certificates will be at:
# /etc/letsencrypt/live/your-domain.com/fullchain.pem
# /etc/letsencrypt/live/your-domain.com/privkey.pem
Copy to Project¶
# Create SSL directory
mkdir -p nginx/ssl
# Copy certificates
sudo cp /etc/letsencrypt/live/your-domain.com/fullchain.pem nginx/ssl/
sudo cp /etc/letsencrypt/live/your-domain.com/privkey.pem nginx/ssl/
# Set permissions
sudo chown -R $USER:$USER nginx/ssl/
chmod 600 nginx/ssl/*.pem
Auto-Renewal¶
Create renewal script:
# Create script
cat > renew-ssl.sh << 'EOF'
#!/bin/bash
# Renew Let's Encrypt certificate
certbot renew --quiet
# Copy new certificates
cp /etc/letsencrypt/live/your-domain.com/fullchain.pem /opt/epidbot/nginx/ssl/
cp /etc/letsencrypt/live/your-domain.com/privkey.pem /opt/epidbot/nginx/ssl/
# Reload nginx
docker compose -f /opt/epidbot/docker-compose.yml restart nginx
EOF
chmod +x renew-ssl.sh
Add to crontab:
sudo crontab -e
# Add this line (runs monthly at midnight on the 1st)
0 0 1 * * /opt/epidbot/renew-ssl.sh
Self-Signed Certificate (Development)¶
For development/testing only:
# Create SSL directory
mkdir -p nginx/ssl
# Generate self-signed certificate
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout nginx/ssl/privkey.pem \
-out nginx/ssl/fullchain.pem \
-subj "/CN=localhost"
Warning
Self-signed certificates will show browser warnings. Only use for development.
SSL Configuration¶
Nginx SSL Settings¶
server {
listen 443 ssl http2;
server_name your-domain.com;
# Certificate paths
ssl_certificate /etc/nginx/ssl/fullchain.pem;
ssl_certificate_key /etc/nginx/ssl/privkey.pem;
# Session settings
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
# Modern TLS
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
# HSTS
add_header Strict-Transport-Security "max-age=63072000" always;
}
HTTP to HTTPS Redirect¶
Certificate Chain¶
For some providers, you need to include the chain:
Verify SSL¶
Check Certificate¶
# Check expiration
openssl x509 -in nginx/ssl/fullchain.pem -noout -dates
# Check details
openssl x509 -in nginx/ssl/fullchain.pem -noout -text
Online Testing¶
Use SSL Labs to test your configuration.
Command Line Testing¶
# Test connection
openssl s_client -connect your-domain.com:443 -servername your-domain.com
# Check certificate
echo | openssl s_client -connect your-domain.com:443 2>/dev/null | openssl x509 -noout -dates
Troubleshooting¶
Certificate not found¶
# Check files exist
ls -la nginx/ssl/
# Check permissions
chmod 644 nginx/ssl/fullchain.pem
chmod 600 nginx/ssl/privkey.pem
Browser warnings¶
- Ensure certificate matches domain
- Check certificate chain is complete
- Verify system time is correct
Certificate expired¶
# Check expiration
openssl x509 -in nginx/ssl/fullchain.pem -noout -dates
# Renew Let's Encrypt
sudo certbot renew
sudo cp /etc/letsencrypt/live/your-domain.com/*.pem nginx/ssl/
docker compose restart nginx
Security Best Practices¶
- Use strong ciphers: Only allow TLS 1.2+
- Enable HSTS: Force HTTPS connections
- Regular renewal: Auto-renew Let's Encrypt
- Protect keys: Set restrictive permissions on privkey.pem
- Monitor expiration: Set up alerts for certificate expiry