
Let's Encrypt คือ Certificate Authority (CA) ที่ออก SSL Certificate ฟรี ไม่มีค่าใช้จ่าย รองรับมาตรฐาน DV (Domain Validated) บริหารโดย Internet Security Research Group (ISRG) ซึ่งได้รับการสนับสนุนจาก Mozilla, Google, Cisco และบริษัทเทคโนโลยีชั้นนำ
Certbot คือ ACME client ที่ Electronic Frontier Foundation (EFF) พัฒนาขึ้นเพื่อทำให้การออกและต่ออายุ Let's Encrypt Certificate เป็นเรื่องง่าย รองรับ Nginx, Apache และ standalone mode
ก่อนเริ่มติดตั้ง Certbot ให้ตรวจสอบให้ครบดังนี้:
| รายการ | รายละเอียด | สถานะ |
|---|---|---|
| VPS Ubuntu | Ubuntu 20.04 / 22.04 / 24.04 | ✅ ต้องมี |
| Nginx ติดตั้งแล้ว | version 1.18 ขึ้นไปแนะนำ | ✅ ต้องมี |
| โดเมนชี้ IP แล้ว | A Record → IP ของ VPS | ✅ ต้องมี |
| Port 80, 443 เปิด | Certbot ใช้ HTTP challenge | ✅ ต้องมี |
| สิทธิ์ root/sudo | ติดตั้ง package ต้องใช้ | ✅ ต้องมี |
ตรวจสอบว่า Nginx ทำงานอยู่:
sudo systemctl status nginx
# ต้องเห็น Active: active (running)
แนะนำให้ติดตั้งผ่าน snap เพราะได้เวอร์ชันล่าสุดเสมอ และอัปเดตอัตโนมัติ:
# อัพเดต package list
sudo apt update
# ติดตั้ง snapd (Ubuntu 20.04+ มีแล้ว)
sudo apt install -y snapd
# อัพเดต snap core
sudo snap install core
sudo snap refresh core
# ติดตั้ง certbot ผ่าน snap
sudo snap install --classic certbot
# สร้าง symlink
sudo ln -s /snap/bin/certbot /usr/bin/certbot
# ตรวจสอบเวอร์ชัน
certbot --version
sudo apt remove certbot
Certbot มี plugin สำหรับ Nginx โดยเฉพาะ ซึ่งจะตั้งค่า HTTPS ให้อัตโนมัติ:
# ออก Certificate และตั้งค่า Nginx อัตโนมัติ
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
# หรือถ้าต้องการออก Certificate อย่างเดียว ไม่แก้ Nginx
sudo certbot certonly --nginx -d yourdomain.com -d www.yourdomain.com
Certbot จะถามอีเมลสำหรับรับแจ้งเตือนและยืนยัน Terms of Service จากนั้นจะออก Certificate เก็บที่:
/etc/letsencrypt/live/yourdomain.com/fullchain.pem # Certificate
/etc/letsencrypt/live/yourdomain.com/privkey.pem # Private Key
Wildcard SSL ครอบคลุมทุก subdomain (*.yourdomain.com) ต้องใช้ DNS Challenge:
sudo certbot certonly --manual --preferred-challenges dns \
-d "yourdomain.com" -d "*.yourdomain.com"
จากนั้น Certbot จะให้คุณเพิ่ม TXT record ในโดเมน รอ DNS propagate แล้วกด Enter เพื่อดำเนินการต่อ
ถ้าใช้คำสั่ง --nginx Certbot จะแก้ไขไฟล์ config ให้อัตโนมัติ แต่ถ้าต้องการตั้งเองให้ใช้ template นี้:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
return 301 https://$host$request_uri;
}
server {
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;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
root /var/www/yourdomain.com;
index index.html index.php;
location / {
try_files $uri $uri/ =404;
}
}
# ทดสอบ config
sudo nginx -t
# โหลด Nginx ใหม่
sudo systemctl reload nginx
HSTS บังคับให้ Browser ใช้ HTTPS เสมอ เพิ่มความปลอดภัยอีกชั้น:
# ใน server block 443
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
Let's Encrypt Certificate มีอายุ 90 วัน Certbot จะตั้ง systemd timer หรือ cron job ให้อัตโนมัติเมื่อติดตั้งผ่าน snap
# ตรวจสอบ timer
sudo systemctl list-timers | grep certbot
# หรือเช็ค cron
sudo crontab -l | grep certbot
ทดสอบการต่ออายุโดยไม่ออก Certificate จริง (dry run):
sudo certbot renew --dry-run
# ต้องเห็น: Congratulations, all simulated renewals succeeded
หลังติดตั้งเสร็จ ตรวจสอบความปลอดภัยด้วยเครื่องมือเหล่านี้:
ssllabs.com/ssltest — ตรวจครบ cipher suites, protocol, certificate chaincurl -I https://yourdomain.com — ดู header และ status codeopenssl s_client -connect yourdomain.com:443 — ดูรายละเอียด certificate# ดูข้อมูล Certificate ที่ออกแล้ว
sudo certbot certificates
# ผลลัพธ์จะแสดง domain, expiry date, certificate path
# เปิด port 80 และ 443 ใน UFW
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload
โดเมนยัง A Record ไม่ชี้มาที่ IP ของ VPS หรือ DNS ยังไม่ propagate รอ 24-48 ชั่วโมงหลังเปลี่ยน DNS
# เช็ค DNS propagation
dig yourdomain.com A +short
# ต้องแสดง IP ของ VPS
# ดู log
sudo journalctl -u snap.certbot.renew --since "1 day ago"
# หรือดูจาก certbot log
sudo cat /var/log/letsencrypt/letsencrypt.log | tail -50
Certificate และ Private Key ไม่ตรงกัน ให้ออก Certificate ใหม่:
sudo certbot renew --force-renewal -d yourdomain.com
ฟรี 100% ไม่มีค่าใช้จ่ายแอบแฝง Let's Encrypt เป็น non-profit ที่ได้รับการสนับสนุนจาก Mozilla, Google, Cisco การออก, ต่ออายุ ทุกอย่างไม่มีค่าใช้จ่าย
Let's Encrypt เป็น DV SSL (Domain Validated) เหมาะกับ Blog, เว็บทั่วไป SSL ที่ซื้อมีตั้งแต่ DV, OV (Organization Validated) ถึง EV ซึ่งให้ความน่าเชื่อถือสูงกว่าสำหรับธุรกิจและ e-commerce ที่ต้องการยืนยันองค์กร
ถ้าตั้ง auto-renewal ถูกต้องแล้ว Certbot จะต่ออายุอัตโนมัติ ถ้าหมดอายุจริงให้รัน sudo certbot renew --force-renewal แล้ว sudo systemctl reload nginx
ได้ VPS AsiaGB ไทยและสิงคโปร์รองรับ Let's Encrypt เต็มรูปแบบ เพียงตั้งค่า A Record โดเมนให้ชี้มาที่ IP ของ VPS แล้วทำตามขั้นตอนในบทความนี้ได้เลย
Certbot รองรับ Ubuntu 20.04, 22.04 และ 24.04 LTS ทั้งหมด แนะนำให้ติดตั้งผ่าน snap เพราะได้เวอร์ชันล่าสุดเสมอและอัปเดตอัตโนมัติ
Let's Encrypt จำกัดการออก Certificate ที่ 50 Certificate ต่อโดเมนหลักต่อสัปดาห์ และ 5 ครั้งต่อโดเมนเดิมต่อชั่วโมง ในการใช้งานทั่วไปไม่เจอ limit นี้
การติดตั้ง Let's Encrypt SSL ด้วย Certbot บน Nginx VPS ทำได้ใน 5-10 นาที ด้วยคำสั่งเพียงไม่กี่บรรทัด ที่สำคัญคือการตั้งค่า auto-renewal ให้ถูกต้องเพื่อไม่ให้ Certificate หมดอายุโดยไม่รู้ตัว
หากต้องการ SSL ระดับ OV หรือ EV สำหรับธุรกิจที่ต้องการความน่าเชื่อถือสูง AsiaGB มีบริการ SSL Certificate หลายประเภทพร้อมทีมช่วยติดตั้ง
ดู VPS AsiaGB