How HTTPS and TLS Really Work: A Practical Guide
You've probably seen the padlock icon in your browser and know it means "secure." But what actually happens when you visit an HTTPS website? How does your browser know it's talking to the real server and not an impostor? And why does TLS sometimes slow things down? This guide breaks down HTTPS and TLS in practical terms, so you can configure, debug, and secure your web applications with confidence.
What HTTPS Really Is
HTTPS is simply HTTP layered on top of TLS (Transport Layer Security). TLS provides three guarantees:
- Confidentiality: Data is encrypted so eavesdroppers can't read it.
- Integrity: Data can't be modified in transit without detection.
- Authentication: The server proves its identity using a certificate.
Without TLS, HTTP sends everything in plaintext: passwords, cookies, and personal data are visible to anyone on the network path. HTTPS fixes that.
The TLS Handshake in Plain English
Before any encrypted data flows, the client and server perform a handshake to agree on encryption keys and verify identity. Here's what happens in a typical TLS 1.3 handshake (the modern standard):
- Client Hello: The browser sends a list of supported cipher suites, TLS versions, and a random value.
- Server Hello: The server picks a cipher suite, sends its own random value, and provides its certificate chain.
- Key Exchange: Both sides use a key exchange algorithm (like ECDHE) to derive a shared secret without ever transmitting it directly.
- Certificate Verification: The client checks the server's certificate against trusted root CAs, validates the domain name, and checks expiration.
- Finished: Both sides send a MAC to confirm the handshake integrity, and encrypted application data begins.
TLS 1.3 reduces this to a single round trip (1-RTT) and even supports 0-RTT resumption for repeat visitors, cutting latency significantly compared to TLS 1.2.
Certificates: The Trust Anchor
A certificate binds a public key to a domain name and is signed by a Certificate Authority (CA). Browsers and operating systems ship with a store of trusted root CAs. When a server presents its certificate, the client verifies the chain up to a trusted root.
Common certificate types:
- DV (Domain Validated): Proves control of the domain; issued quickly and often free (e.g., Let's Encrypt).
- OV (Organization Validated): Includes verified organization details; takes longer to issue.
- EV (Extended Validation): Highest validation level; historically showed a green bar, but modern browsers no longer emphasize it.
Certificates expire, so automation is essential. Tools like Certbot or ACME clients integrated with your reverse proxy handle renewal automatically.
Configuring HTTPS on Your Server
Here's a minimal Nginx configuration that enables HTTPS with modern TLS settings:
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';
ssl_prefer_server_ciphers off;
# HSTS (enable after testing)
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
location / {
proxy_pass http://localhost:3000;
}
}
server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}
Key points: use TLS 1.2 and 1.3 only, prefer ECDHE cipher suites for forward secrecy, and redirect HTTP to HTTPS. HSTS tells browsers to always use HTTPS for your domain, but test carefully before enabling it with a long max-age.
Common Pitfalls and How to Avoid Them
- Mixed content: Loading HTTP resources on an HTTPS page breaks the padlock. Use relative URLs or ensure all assets are HTTPS.
- Expired certificates: Automate renewal and monitor expiration. A expired cert causes immediate browser warnings.
- Weak protocols: Disable TLS 1.0 and 1.1; they're deprecated and vulnerable.
- Incomplete certificate chains: Servers must send intermediate certificates; otherwise some clients fail. Use tools like SSL Labs to test.
- No HSTS preload: For maximum protection, submit your domain to the HSTS preload list after ensuring all subdomains support HTTPS.
TLS 1.2 vs TLS 1.3: What Changed
| Feature | TLS 1.2 | TLS 1.3 |
|---|---|---|
| Handshake round trips | 2-RTT | 1-RTT (0-RTT with resumption) |
| Key exchange | RSA or ECDHE | ECDHE only (forward secrecy mandatory) |
| Cipher suites | Many, including weak ones | Reduced set, all AEAD |
| 0-RTT data | Not supported | Supported (with replay risk) |
TLS 1.3 is faster and simpler, removing legacy algorithms. Most modern clients support it, but keep TLS 1.2 for older devices.
Debugging TLS Issues
When HTTPS fails, check these:
- Use
openssl s_client -connect example.com:443 -servername example.comto inspect the certificate chain and handshake. - Run
curl -vI https://example.comto see TLS version and cipher negotiated. - Check server logs for handshake errors; Nginx logs SSL errors to the error log.
- Use online SSL testers to get a comprehensive grade and recommendations.
If you work with Nginx logs regularly, the Nginx Log Analyzer can help you spot TLS handshake failures and other issues quickly.
FAQ
What is the difference between HTTPS and TLS?
HTTPS is HTTP over TLS. TLS is the cryptographic protocol that provides encryption, integrity, and authentication. HTTPS is the secure version of HTTP that uses TLS.
Do I need a certificate for internal services?
Yes, for production internal services, use certificates from your own CA or a public CA. Self-signed certificates cause trust issues; consider using a private PKI or tools like mkcert for development.
How often should certificates be renewed?
Modern best practice is 90-day certificates with automated renewal, as offered by Let's Encrypt. Shorter lifetimes reduce risk if a key is compromised.
Ready to secure your site? Start by testing your current TLS configuration with an SSL checker, then apply the Nginx settings above. For a deeper dive into web security, explore our other guides on OWASP Top 10 and XSS prevention.