HTTPS TLS cách hoạt động không cần thuộc lòng nhưng dev phải hiểu cơ bản — debug cert error, config server, optimize handshake. Bài này giải thích đủ deep mà không quá lý thuyết.
Vấn đề HTTPS giải
HTTP plaintext: ISP, wifi public, attacker MITM đọc được password, cookie, payment. HTTPS = HTTP + TLS — encrypt, authenticate server, integrity check.
TLS 1.3 handshake
Client Server
ClientHello (cipher suites, key share) →
← ServerHello (chosen cipher, key share, cert)
Encrypted: { Finished }
{ Finished } →
← { Application data }
{ Application data } →
1-RTT (1 round trip) — chỉ 1 lần đi-về xong. So với TLS 1.2 (2-RTT). Tốc độ tăng 50% cho first request.
Certificate: ai là server?
Certificate = public key + domain + chữ ký CA (Certificate Authority). Browser tin CA → tin cert.
# Kiểm certificate
openssl s_client -connect alodev.vn:443 -servername alodev.vn
# Verify chain
openssl x509 -in cert.pem -text -noout
3 loại validation:
- DV (Domain Validation): verify anh control domain. Let's Encrypt. Đủ cho 99% case.
- OV (Organization): + verify công ty. Hiện ít dùng.
- EV (Extended): + verify pháp nhân. Banking, large e-commerce.
Let's Encrypt với Certbot
# Cài certbot
sudo apt install certbot python3-certbot-nginx
# Auto config nginx + cert
sudo certbot --nginx -d alodev.vn -d www.alodev.vn
# Auto renew (cron đã setup sẵn)
sudo certbot renew --dry-run
Cert valid 90 ngày, auto-renew khi còn 30 ngày. Hoàn toàn free, dùng cho production thật.
Caddy — auto HTTPS easiest
# Caddyfile
alodev.vn {
reverse_proxy localhost:3000
}
Caddy tự lấy + renew Let's Encrypt cert. Không config gì thêm. Default cho deployment đơn giản 2026.
Cipher suite
# Modern (TLS 1.3 only) — recommend
TLS_AES_256_GCM_SHA384
TLS_AES_128_GCM_SHA256
TLS_CHACHA20_POLY1305_SHA256
# Intermediate (support TLS 1.2)
ECDHE-ECDSA-AES256-GCM-SHA384
ECDHE-RSA-AES256-GCM-SHA384
ECDHE-ECDSA-CHACHA20-POLY1305
Quan trọng: ECDHE prefix → ephemeral key → Perfect Forward Secrecy.
Mozilla SSL Configuration Generator: paste server type → generate config sẵn dùng.
HSTS — force HTTPS
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
- Browser remember "luôn HTTPS" cho domain này trong 1 năm
- Chống SSL strip attack
- preload: thêm vào hardcoded list browser (hsts.preload.org)
Cảnh báo: enable HSTS = không revert HTTP trong max-age. Đảm bảo HTTPS đầy đủ trước.
Security header phụ trợ
// Express helmet
import helmet from 'helmet'
app.use(helmet()) // set 15+ security header tự động
// Hoặc manual:
app.use((req, res, next) => {
res.setHeader('Strict-Transport-Security', 'max-age=31536000; includeSubDomains')
res.setHeader('X-Frame-Options', 'DENY')
res.setHeader('X-Content-Type-Options', 'nosniff')
res.setHeader('Referrer-Policy', 'strict-origin-when-cross-origin')
res.setHeader('Permissions-Policy', 'geolocation=(), camera=()')
next()
})
Test bằng SSL Labs
ssllabs.com/ssltest/analyze.html?d=alodev.vn — giả lập handshake, đánh giá cipher, certificate, header. Mục tiêu A+ score.
Kết luận
HTTPS TLS không phải optional 2026 — Google rank hạ HTTP, browser warning user "Not Secure". Setup Let's Encrypt 5 phút, free, auto. Combine HSTS + helmet + SSL Labs test. Đọc OWASP Top 10 để hiểu cách HTTPS phối hợp với defense layer khác.