How HTTPS and TLS Really Work: A Practical Guide
You've probably seen the padlock icon in your browser and assumed the connection is secure. But what actually happens when you visit an HTTPS site? Why do certificates expire, and why do some sites still show warnings? Understanding the TLS handshake and certificate validation helps you debug issues, configure servers correctly, and explain security to your team.
This guide walks through the practical mechanics of HTTPS and TLS—no cryptic math, just the concepts and steps that matter for web developers and system administrators.
What HTTPS Really Means
HTTPS is HTTP over TLS (Transport Layer Security). TLS provides three guarantees:
- Encryption: Data exchanged between client and server is unreadable to eavesdroppers.
- Authentication: The server proves its identity using a certificate signed by a trusted authority.
- Integrity: Data cannot be modified in transit without detection.
TLS is the successor to SSL (Secure Sockets Layer). Although people still say "SSL certificate," modern systems use TLS 1.2 or 1.3.
The TLS Handshake in Plain English
Before any HTTP data is sent, the client and server perform a handshake to agree on encryption keys. 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 chooses a cipher suite, sends its certificate, and provides its own random value.
- Key Exchange: Using ephemeral Diffie-Hellman, both sides derive a shared secret without transmitting it.
- Finished: Both sides verify the handshake and start encrypting application data.
TLS 1.3 reduces the handshake to one round trip (1-RTT) and supports 0-RTT resumption for repeat connections. TLS 1.2 requires two round trips, which adds latency.
You can see the handshake in action using openssl s_client:
openssl s_client -connect example.com:443 -tls1_3 -servername example.com
This command connects to the server, prints the certificate chain, and shows the negotiated cipher suite.
Certificates: Trust Anchors of the Web
A certificate binds a public key to a domain name and is signed by a Certificate Authority (CA). Browsers trust a set of root CAs preinstalled in the operating system or browser.
When a server presents its certificate, the client checks:
- Validity period: Is the certificate expired or not yet valid?
- Domain match: Does the certificate cover the requested hostname (via Subject Alternative Names)?
- Chain of trust: Is the certificate signed by a trusted CA, and is the chain complete?
- Revocation status: Has the certificate been revoked? (Checked via OCSP or CRL.)
If any check fails, the browser shows a warning. Common causes include expired certificates, self-signed certificates in production, or missing intermediate certificates.
How to Inspect a Certificate
Use OpenSSL to view certificate details:
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates -subject -issuer
This prints the validity dates, subject (domain), and issuer (CA).
Debugging Common HTTPS Issues
Even with automation, HTTPS problems occur. Here are frequent issues and how to resolve them.
| Issue | Symptom | Fix |
|---|---|---|
| Expired certificate | Browser warning "Certificate has expired" | Renew certificate and reload server |
| Missing intermediate | "Certificate chain incomplete" on some devices | Configure server to send full chain |
| Mixed content | Padlock with warning; insecure resources blocked | Load all resources over HTTPS |
| Wrong hostname | "Certificate is not valid for this domain" | Reissue certificate with correct SANs |
For mixed content, check the browser console. Modern browsers block active mixed content (scripts, stylesheets) and may auto-upgrade passive content (images).
Best Practices for HTTPS Configuration
Beyond installing a certificate, configure your server for security and performance:
- Use TLS 1.2 or 1.3: Disable older protocols (TLS 1.0/1.1, SSLv3).
- Enable HSTS: Send the
Strict-Transport-Securityheader to force HTTPS for future visits. - Use strong cipher suites: Prefer AEAD ciphers like AES-GCM or ChaCha20-Poly1305.
- Enable OCSP stapling: The server includes revocation status in the handshake, reducing client lookups.
- Consider certificate pinning: For mobile apps, pin the public key to prevent MITM attacks (use with caution).
Here's a sample Nginx configuration snippet:
server {
listen 443 ssl http2;
server_name example.com;
ssl_certificate /etc/ssl/certs/example.com.fullchain.pem;
ssl_certificate_key /etc/ssl/private/example.com.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256';
ssl_prefer_server_ciphers off;
add_header Strict-Transport-Security "max-age=63072000" always;
}
Always test your configuration with tools like SSL Labs or testssl.sh after changes.
FAQ
What is the difference between TLS and SSL?
TLS is the modern, secure protocol; SSL is its deprecated predecessor. People often say "SSL" when they mean TLS, but all current HTTPS uses TLS (version 1.2 or 1.3).
Why do I see a certificate warning even though the certificate is valid?
Common causes include an incomplete certificate chain (missing intermediate), a hostname mismatch, or a client clock set incorrectly. Use OpenSSL or browser developer tools to inspect the certificate details.
Does HTTPS slow down my website?
Modern TLS (especially 1.3) has minimal overhead. With session resumption and HTTP/2, HTTPS can be faster than HTTP due to multiplexing. The handshake adds a small initial cost, but caching and TLS 1.3 reduce it significantly.
If you need to analyze server logs to spot TLS errors or unusual traffic patterns, the Nginx Log Analyzer can help you parse and visualize log data quickly.