SSL/TLS & HTTPS
How HTTPS encrypts web traffic, how certificates work, and how to get free certificates for your domain
Skills taught: deployment.ssl, deployment.tls, deployment.https, deployment.certificates, deployment.lets-encrypt, deployment.hsts
Why HTTPS is mandatory
HTTP sends all data in plain text — anyone between you and the server (your ISP, a coffee shop's Wi-Fi router, a government network) can read your passwords, form submissions, and session cookies. HTTPS adds TLS encryption that makes intercepted traffic unreadable. Beyond security, HTTPS is now required: browsers mark HTTP sites as 'Not Secure', Google ranks HTTPS sites higher in search, and modern browser APIs (geolocation, push notifications, service workers) require HTTPS.
How TLS works (simplified)
BEFORE THE HANDSHAKE:
Server has a certificate (like a passport):
- Contains the server's public key
- Signed by a Certificate Authority (CA) that browsers trust
- Proves the server really owns myapp.com
THE TLS 1.3 HANDSHAKE (1 round trip):
Client → Server:
'Hello! I support TLS 1.3. Here are my cipher preferences.
Here's my key share (Diffie-Hellman public key).'
Server → Client:
'Great! I'll use [chosen cipher].
Here's my certificate (so you can verify I own myapp.com).
Here's my key share.
Here's the first encrypted data (server can start immediately)'
Client:
- Verifies the certificate is valid and signed by a trusted CA
- Verifies the certificate is for 'myapp.com' (matches domain)
- Verifies the certificate hasn't expired
- Both sides derive the same symmetric encryption key
(using Diffie-Hellman math — no secret transmitted!)
All subsequent data is encrypted with symmetric key (AES-256)
CERTIFICATE AUTHORITIES (CAs):
Trusted organizations that verify you own a domain before signing
Browsers and OSes come with a list of ~150 trusted CAs
If a CA signs your certificate → browsers trust your site
Major CAs: Let's Encrypt (free), DigiCert, Comodo, GlobalSign
Getting free certificates — Let's Encrypt
# Let's Encrypt is a free, automated CA backed by Mozilla, Google, and others
# Certbot is the official Let's Encrypt client
# Install Certbot on Ubuntu
sudo apt install certbot python3-certbot-nginx
# Get certificate + configure Nginx automatically
sudo certbot --nginx -d myapp.com -d www.myapp.com
# Certbot:
# 1. Verifies you control myapp.com (places a file on your server)
# 2. CA verifies the file exists via HTTP
# 3. Issues a 90-day certificate
# 4. Configures Nginx to use it
# 5. Sets up auto-renewal (checks twice daily, renews 30 days before expiry)
# After certbot, your Nginx config will have:
# listen 443 ssl;
# ssl_certificate /etc/letsencrypt/live/myapp.com/fullchain.pem;
# ssl_certificate_key /etc/letsencrypt/live/myapp.com/privkey.pem;
# include /etc/letsencrypt/options-ssl-nginx.conf;
# Test auto-renewal:
sudo certbot renew --dry-run
# Manual renewal (usually not needed):
sudo certbot renew
Platform-managed certificates — zero-config HTTPS
VERCEL:
Add your domain → HTTPS is automatic
Uses Let's Encrypt behind the scenes
Zero configuration needed
NETLIFY:
Same — custom domain → free TLS certificate
One-click force HTTPS (redirects HTTP → HTTPS)
CLOUDFLARE:
Two options:
1. Full: Cloudflare ↔ Origin (your server must have ANY valid cert)
2. Full (Strict): Cloudflare ↔ Origin (origin must have valid cert)
Cloudflare issues free certs for the browser ↔ Cloudflare leg
Optional: Cloudflare Origin CA cert (free, 15-year validity)
AWS:
ACM (AWS Certificate Manager) → free certs for CloudFront/ALB
Works via DNS validation (add a CNAME record to prove domain ownership)
Certs auto-renew
For any platform-hosted app: just point your domain → use the platform's
HTTPS support. You never need to run Certbot manually.
HTTPS best practices
server {
listen 80;
server_name myapp.com www.myapp.com;
# Redirect all HTTP to HTTPS
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name myapp.com www.myapp.com;
ssl_certificate /etc/letsencrypt/live/myapp.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/myapp.com/privkey.pem;
# Modern TLS configuration
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;
ssl_prefer_server_ciphers off;
# HSTS: tell browsers to ALWAYS use HTTPS for 1 year
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
# Security headers
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header Referrer-Policy strict-origin-when-cross-origin;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Frequently Asked Questions
What is the difference between SSL and TLS?
SSL (Secure Sockets Layer) is the older protocol (last version: SSL 3.0, 1996). TLS (Transport Layer Security) is its successor — TLS 1.0 replaced SSL 3.0. All modern connections use TLS 1.2 or 1.3. But the industry still says 'SSL certificate' colloquially, even though every certificate is technically used with TLS. SSL 2.0 and 3.0 are deprecated and insecure — your server should only accept TLS 1.2 and TLS 1.3.