正在加载,请稍候…

HTTPS and TLS Certificates: Let's Encrypt, mTLS, and HSTS

Manage TLS in production — Let's Encrypt automation, Nginx TLS config, mTLS for service auth, HSTS, and OCSP stapling.

Let's Encrypt: Free Automated TLS

# Install and get certificate
apt install certbot python3-certbot-nginx
certbot --nginx -d example.com -d www.example.com

# Auto-renewal
systemctl enable certbot.timer
certbot renew --dry-run

Nginx TLS Configuration (A+ Rating)

server {
    listen 443 ssl http2;
    server_name example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384;
    ssl_prefer_server_ciphers off;

    add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 8.8.8.8 valid=300s;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 1d;
}

server { listen 80; server_name example.com; return 301 https://$host$request_uri; }

mTLS for Service-to-Service Auth

# Generate CA
openssl genrsa -out ca.key 4096
openssl req -x509 -new -key ca.key -sha256 -days 3650 -out ca.crt -subj "/CN=Internal CA"

# Generate service cert
openssl genrsa -out service.key 2048
openssl req -new -key service.key -out service.csr -subj "/CN=service-a"
openssl x509 -req -in service.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out service.crt -days 365
# Nginx mTLS
ssl_client_certificate /etc/ssl/ca.crt;
ssl_verify_client on;

Certificate Expiry Monitoring

echo | openssl s_client -servername example.com -connect example.com:443 2>/dev/null   | openssl x509 -noout -dates

-> Encode certificates with the Base64 Converter.