Cài SSL/TLS trên VPS: Let's Encrypt Miễn Phí
HTTPS là yêu cầu bắt buộc cho mọi website hiện đại. Let's Encrypt cung cấp chứng chỉ SSL/TLS miễn phí, tự động gia hạn. Hướng dẫn này giúp bạn cài đặt và cấu hình HTTPS hoàn chỉnh cho VPS offshore AnubizHost chỉ trong vài phút.
Need this done for your project?
We implement, you ship. Async, documented, done in days.
Cài Đặt Certbot
Certbot là công cụ chính thức để lấy chứng chỉ Let's Encrypt:
apt update
apt install -y certbot python3-certbot-nginxĐảm bảo domain của bạn đã trỏ DNS về IP của VPS trước khi lấy chứng chỉ. Kiểm tra:
dig yourdomain.com +short
# Kết quả phải là IP VPS của bạnLấy chứng chỉ (Nginx phải đang chạy):
certbot --nginx -d yourdomain.com -d www.yourdomain.comCertbot tự động sửa cấu hình Nginx để enable HTTPS và redirect HTTP sang HTTPS.
Cấu Hình Nginx HTTPS Tối Ưu
Sau khi cài Certbot, cấu hình bảo mật nâng cao:
nano /etc/nginx/sites-available/yourdomain.comserver {
listen 443 ssl http2;
server_name yourdomain.com www.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/yourdomain.com/chain.pem;
# Bảo mật TLS
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;
ssl_prefer_server_ciphers off;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 1d;
# HSTS
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
}Gia Hạn Tự Động Chứng Chỉ
Chứng chỉ Let's Encrypt có hạn 90 ngày. Certbot tự động thiết lập cron/systemd timer:
# Kiểm tra timer tự động
systemctl status certbot.timer
# Test gia hạn (không thực sự gia hạn)
certbot renew --dry-runNếu muốn thiết lập thủ công:
crontab -e
# Thêm:
0 12 * * * /usr/bin/certbot renew --quiet --post-hook "systemctl reload nginx"Kiểm tra ngày hết hạn chứng chỉ:
certbot certificates
openssl x509 -in /etc/letsencrypt/live/yourdomain.com/cert.pem -noout -datesWildcard Certificate và DNS Challenge
Wildcard cert (*.yourdomain.com) yêu cầu DNS challenge:
certbot certonly --manual --preferred-challenges dns -d "yourdomain.com" -d "*.yourdomain.com"Certbot sẽ yêu cầu bạn tạo TXT record trong DNS. Thêm record, đợi propagate (1-5 phút) rồi tiếp tục.
Với Cloudflare, dùng plugin tự động:
apt install -y python3-certbot-dns-cloudflare
nano /etc/letsencrypt/cloudflare.inidns_cloudflare_api_token = your_api_tokenchmod 600 /etc/letsencrypt/cloudflare.ini
certbot certonly --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/cloudflare.ini -d "yourdomain.com" -d "*.yourdomain.com"Related Services
Why Anubiz Host
Ready to get started?
Skip the research. Tell us what you need, and we'll scope it, implement it, and hand it back — fully documented and production-ready.