---
title: "Trên Rocky Linux 9: Hướng dẫn cài đặt Certbot gia hạn SSL Wildcard qua Cloudflare DNS"
description: "Hướng dẫn cài đặt Certbot và plugin dns-cloudflare trên Rocky Linux 9 để cấp phát và tự động gia hạn chứng chỉ SSL Wildcard (*.domain.com) an toàn."
canonical: "https://thuecloud.vn/tren-rocky-linux-9-huong-dan-cai-dat-certbot-gia-han-ssl-wildcard-qua-cloudflare-dns"
markdown_url: "https://thuecloud.vn/tren-rocky-linux-9-huong-dan-cai-dat-certbot-gia-han-ssl-wildcard-qua-cloudflare-dns.md"
locale: "vi"
kind: "article"
published_at: "2026-11-22T16:18:29.922Z"
updated_at: "2026-11-22T16:18:29.248Z"
site: "ThueCloud.Vn"
estimated_tokens: 1712
---
# Trên Rocky Linux 9: Hướng dẫn cài đặt Certbot gia hạn SSL Wildcard qua Cloudflare DNS

> Hướng dẫn cài đặt Certbot và plugin dns-cloudflare trên Rocky Linux 9 để cấp phát và tự động gia hạn chứng chỉ SSL Wildcard (*.domain.com) an toàn.

- Canonical HTML: https://thuecloud.vn/tren-rocky-linux-9-huong-dan-cai-dat-certbot-gia-han-ssl-wildcard-qua-cloudflare-dns
- Markdown URL: https://thuecloud.vn/tren-rocky-linux-9-huong-dan-cai-dat-certbot-gia-han-ssl-wildcard-qua-cloudflare-dns.md
- Organization: ThueCloud.Vn
- Support Email: support@thuecloud.vn
- Hotline: 03333 499 48
- Published: 2026-11-22
- Updated: 2026-11-22

## Mục lục

- Tạo Cloudflare Scoped API Token an toàn
  - So sánh HTTP-01 vs DNS-01 Challenge
- Cài đặt Certbot và cấp chứng chỉ Wildcard
- Câu hỏi thường gặp (FAQ)
  - Tại sao Certbot báo lỗi Unsafe permissions on credentials configuration file?
  - Nếu dùng certonly thì Nginx có tự động reload sau khi gia hạn SSL không?
  - Có cần tắt Cloudflare Proxy (đám mây cam) khi chạy DNS-01 challenge không?

Khi vận hành nhiều subdomain trên một [VPS Việt Nam](https://thuecloud.vn/vps-viet-nam) chạy **Rocky Linux 9** (như `api.`, `admin.`, `app.`), việc cấp chứng chỉ SSL lẻ cho từng tên miền rất bất tiện. Sử dụng **Certbot** kết hợp **Cloudflare DNS-01 challenge** giúp bạn cấp phát và tự động gia hạn **SSL Wildcard (`*.yourdomain.com`)** mà không cần mở cổng 80 hay tắt dịch vụ web.

> **Tóm tắt nhanh (TL;DR):**
> - Tạo Cloudflare **API Token** (Scoped Token chỉ có quyền `Zone:DNS:Edit` cho đúng domain, không dùng Global API Key).
> - Cài đặt `certbot` và `python3-certbot-dns-cloudflare` qua `dnf` (EPEL) hoặc `pip`/venv.
> - Kiểm tra gia hạn tự động bằng `certbot renew --dry-run` và tích hợp `deploy-hook` reload Nginx.
> - *Cập nhật: 11/2026*

## 1. Tạo Cloudflare Scoped API Token an toàn

Trong Cloudflare Dashboard > **My Profile > API Tokens > Create Token**, chọn template **Edit zone DNS** với quyền tối thiểu:
- **Permissions:** `Zone` -> `DNS` -> `Edit`
- **Zone Resources:** `Include` -> `Specific zone` -> `yourdomain.com`

Lưu token vào file `/root/.secrets/cloudflare.ini` trên Rocky Linux 9 và khóa quyền truy cập:

```bash
sudo mkdir -p /root/.secrets
cat <<'EOF' | sudo tee /root/.secrets/cloudflare.ini
dns_cloudflare_api_token = YOUR_SCOPED_CLOUDFLARE_API_TOKEN
EOF
sudo chmod 600 /root/.secrets/cloudflare.ini
```

### So sánh HTTP-01 vs DNS-01 Challenge

| Tiêu chí | HTTP-01 Challenge | DNS-01 Challenge (Cloudflare) |
| :--- | :--- | :--- |
| **Hỗ trợ Wildcard (`*.domain`)** | Không | **Có** |
| **Yêu cầu mở Port 80 công khai** | Bắt buộc | Không (chạy được cho server nội bộ) |
| **Tốc độ xác thực** | Tức thì | 10–30 giây (chờ propagation DNS) |

## 2. Cài đặt Certbot và cấp chứng chỉ Wildcard

```bash
sudo dnf install -y epel-release
sudo dnf install -y certbot python3-certbot-dns-cloudflare

# Cấp chứng chỉ cho cả root domain và wildcard
sudo certbot certonly \
  --dns-cloudflare \
  --dns-cloudflare-credentials /root/.secrets/cloudflare.ini \
  --dns-cloudflare-propagation-seconds 20 \
  -d yourdomain.com -d '*.yourdomain.com'
```

Kích hoạt systemd timer để tự động gia hạn mỗi 60 ngày và tự reload Nginx khi có chứng chỉ mới:

```bash
sudo systemctl enable --now certbot-renew.timer
sudo certbot renew --dry-run --deploy-hook "systemctl reload nginx"
```

Trong tổng thể [giải pháp vận hành DevOps](https://thuecloud.vn/giai-phap), việc tự động hóa SSL Wildcard giúp bạn triển khai nhanh các tính năng tối ưu như [HTTP Early Hints 103](https://thuecloud.vn/http-early-hints-103-tinh-chinh-tham-so-hieu-nang-va-gioi-han-tai-nguyen-production), đồng thời kết hợp bảo vệ chuỗi cung ứng bằng [Cosign Container Signing](https://thuecloud.vn/cosign-container-signing-phan-tich-loi-thuong-gap-va-quy-trinh-xu-ly-su-co-nhanh) hoặc tham khảo [kinh nghiệm Anycast DNS](https://thuecloud.vn/anycast-dns-latency-reduction-kinh-nghiem-van-hanh-thuc-te-va-so-sanh-phuong-an-thay-the).

> **Triển khai Web Server & SSL tự động tại ThueCloud.Vn:** Chọn **VPS VN 1** (`45.000đ/tháng` năm) hoặc **VPS VN 2** (`78.000đ/tháng` năm) trên **KVM Enterprise NVMe** tại `vn-hn`. Miễn phí **VAT 0%**, **SLA 99,9%**, hoàn tiền **07 ngày**. Xem thêm tại [Bảng giá ThueCloud](https://thuecloud.vn/pricing).

## Câu hỏi thường gặp (FAQ)

### Tại sao Certbot báo lỗi `Unsafe permissions on credentials configuration file`?
Vì file `/root/.secrets/cloudflare.ini` đang có quyền đọc cho group hoặc world. Bạn bắt buộc phải chạy `chmod 600 /root/.secrets/cloudflare.ini`.

### Nếu dùng `certonly` thì Nginx có tự động reload sau khi gia hạn SSL không?
Không. Lệnh `certonly` chỉ lấy chứng chỉ về `/etc/letsencrypt/live/...`. Bạn cần thêm `--deploy-hook "systemctl reload nginx"` hoặc đặt script trong `/etc/letsencrypt/renewal-hooks/deploy/`.

### Có cần tắt Cloudflare Proxy (đám mây cam) khi chạy DNS-01 challenge không?
Không cần. Phương thức DNS-01 xác thực qua bản ghi `_acme-challenge` TXT trong DNS, hoàn toàn không bị ảnh hưởng bởi trạng thái đám mây cam của Cloudflare.

## References / Sources

- https://eff-certbot.readthedocs.io/en/stable/install.html
- https://certbot-dns-cloudflare.readthedocs.io/en/stable/
- https://developers.cloudflare.com/fundamentals/api/get-started/create-token/

---

## Navigation & Machine-Readable Endpoints

- [Site Summary (llms.txt)](https://thuecloud.vn/llms.txt)
- [Full Technical Reference (llms-full.txt)](https://thuecloud.vn/llms-full.txt)
- [Pricing Catalog (Markdown)](https://thuecloud.vn/pricing.md)
- [Blog & Technical Guides (Markdown)](https://thuecloud.vn/blog.md)
- [XML Sitemap](https://thuecloud.vn/sitemap.xml)
