How HTTPS and TLS Really Work: Handshake, Certificates, and Best Practices
You type a URL, hit Enter, and the page loads securely. But what actually happens when you use HTTPS? Many developers treat TLS as a black box—until something breaks, like a certificate error or a performance issue. This article unpacks how HTTPS and TLS really work, from the handshake to certificate validation, with practical tips you can apply today.
What HTTPS and TLS Actually Are
HTTPS is HTTP over TLS (Transport Layer Security). TLS is a cryptographic protocol that provides three guarantees:
- Confidentiality: Data is encrypted so eavesdroppers can't read it.
- Integrity: Data can't be modified in transit without detection.
- Authentication: You're talking to the server you intended to reach, verified via certificates.
TLS evolved from SSL (Secure Sockets Layer). SSL is deprecated; modern systems use TLS 1.2 or 1.3. When you see “SSL certificate,” it's actually a TLS certificate.
The TLS Handshake in Plain English
Before any HTTP data flows, the client and server perform a handshake to agree on encryption parameters and verify identities. Here's a simplified version for TLS 1.3, the current standard:
- Client Hello: The client sends supported TLS versions, cipher suites, 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 parties use ephemeral Diffie-Hellman to derive a shared secret without transmitting it.
- Finished: Both sides verify the handshake integrity and switch to encrypted communication.
TLS 1.3 reduces the handshake to one round trip, improving latency. TLS 1.2 requires two round trips and supports older cipher suites, some of which are insecure.
What About the Certificate?
The server's certificate contains its public key and identity information, signed by a Certificate Authority (CA). The client verifies:
- The certificate is signed by a trusted CA (or chain to one).
- The certificate is valid for the requested domain (Subject Alternative Names).
- The certificate is within its validity period.
- The certificate hasn't been revoked (via OCSP or CRL).
If any check fails, the browser shows a warning. That's why an expired certificate breaks your site.
Encryption in Transit: Symmetric vs Asymmetric
TLS uses both types of encryption:
- Asymmetric (public-key) cryptography: Used during the handshake to authenticate the server and securely exchange keys. Slow but solves key distribution.
- Symmetric encryption: Used for bulk data after the handshake. Fast and efficient (e.g., AES-GCM, ChaCha20-Poly1305).
The handshake establishes a shared symmetric key that only the client and server know. Subsequent HTTP messages are encrypted with that key.
Practical TLS Configuration for Web Servers
Misconfiguration is common. Follow these guidelines to avoid weaknesses:
- Use TLS 1.2 or 1.3 only. Disable TLS 1.0 and 1.1.
- Prefer strong cipher suites (e.g., ECDHE with AES-GCM or ChaCha20). Disable CBC-mode ciphers if possible.
- Enable HTTP Strict Transport Security (HSTS) to force HTTPS.
- Use OCSP Stapling to improve revocation checking performance.
- Automate certificate renewal with Let's Encrypt and ACME clients.
Here's a sample Nginx configuration snippet for modern TLS:
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-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305';
ssl_prefer_server_ciphers off;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
}
Test your configuration with SSL Labs or similar tools to catch issues.
Common HTTPS Pitfalls and How to Avoid Them
| Pitfall | Consequence | Fix |
|---|---|---|
| Expired certificate | Browser warnings, lost trust | Automate renewal with monitoring |
| Mixed content | Insecure elements on HTTPS page | Serve all resources over HTTPS |
| Weak ciphers | Vulnerable to attacks | Disable legacy ciphers |
| Missing HSTS | Downgrade attacks possible | Add HSTS header |
FAQ
What is the difference between HTTPS and TLS?
HTTPS is HTTP layered on top of TLS. TLS is the cryptographic protocol that secures the connection; HTTPS is the secure version of the HTTP protocol.
Do I need a certificate for local development?
Not strictly, but using a self-signed certificate or a tool like mkcert helps mimic production and avoid mixed-content issues. Browsers will warn about self-signed certs unless you trust them locally.
How often should certificates be renewed?
With Let's Encrypt, certificates are valid for 90 days and should be auto-renewed. Commercial certificates can last up to 398 days (as of current CA/Browser Forum rules), but shorter lifetimes are recommended.
Ready to inspect your server's TLS setup? Use our Nginx Log Analyzer to spot SSL errors and handshake failures in your logs.