---
title: "Triển khai WordPress (OpenLiteSpeed + LSCache): cấu hình biến môi trường, secrets và SSL Let's Encrypt"
description: "Hướng dẫn triển khai WordPress trên OpenLiteSpeed + LSCache: bảo mật wp-config.php bằng biến môi trường/secrets, tối ưu quyền file và cài SSL Let's Encrypt tự động."
canonical: "https://thuecloud.vn/trien-khai-wordpress-openlitespeed-lscache-cau-hinh-bien-moi-truong-secrets-va-ssl-let-s-encrypt"
markdown_url: "https://thuecloud.vn/trien-khai-wordpress-openlitespeed-lscache-cau-hinh-bien-moi-truong-secrets-va-ssl-let-s-encrypt.md"
locale: "vi"
kind: "article"
published_at: "2026-11-22T16:18:21.925Z"
updated_at: "2026-11-22T16:18:18.845Z"
site: "ThueCloud.Vn"
estimated_tokens: 2144
---
# Triển khai WordPress (OpenLiteSpeed + LSCache): cấu hình biến môi trường, secrets và SSL Let's Encrypt

> Hướng dẫn triển khai WordPress trên OpenLiteSpeed + LSCache: bảo mật wp-config.php bằng biến môi trường/secrets, tối ưu quyền file và cài SSL Let's Encrypt tự động.

- Canonical HTML: https://thuecloud.vn/trien-khai-wordpress-openlitespeed-lscache-cau-hinh-bien-moi-truong-secrets-va-ssl-let-s-encrypt
- Markdown URL: https://thuecloud.vn/trien-khai-wordpress-openlitespeed-lscache-cau-hinh-bien-moi-truong-secrets-va-ssl-let-s-encrypt.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

- Bảo vệ Secrets và wp-config.php trên OpenLiteSpeed
- Cài đặt và tự động gia hạn SSL Let's Encrypt cho OpenLiteSpeed
  - Bảng checklist bảo mật & tối ưu WordPress trên OpenLiteSpeed
- Câu hỏi thường gặp (FAQ)
  - Tại sao sau khi sửa cấu hình trên OpenLiteSpeed WebAdmin hoặc file .htaccess lại chưa có hiệu lực?
  - Làm sao để dùng HTTPS nhưng không bị lỗi Mixed Content trong WordPress?
  - Gói VPS nào của ThueCloud phù hợp để chạy WordPress + OpenLiteSpeed + WooCommerce?

Kết hợp **OpenLiteSpeed (OLS)** và plugin **LiteSpeed Cache (LSCache)** trên [VPS Việt Nam](https://thuecloud.vn/vps-viet-nam) là một trong những kiến trúc tối ưu nhất cho WordPress hiện nay, cho phép xử lý hàng nghìn truy vấn đồng thời với TTFB dưới 50ms. Tuy nhiên, lỗi phổ biến của nhiều quản trị viên là để nguyên mật khẩu DB và Salt Keys dạng văn bản thuần trong `wp-config.php` nằm ngay thư mục public, hoặc quên cấu hình tự động gia hạn **SSL Let's Encrypt** trên WebAdmin Console của OpenLiteSpeed.

> **Tóm tắt nhanh (TL;DR):**
> - Tách thông tin nhạy cảm (`DB_PASSWORD`, `AUTH_KEY`, SMTP password) ra file cấu hình nằm **bên ngoài webroot** (`public_html`) với quyền `0600`.
> - Cấu hình **Certbot** dùng webroot challenge kết hợp hook `systemctl reload lsws` để OpenLiteSpeed tự nhận chứng chỉ SSL mới mỗi 60 ngày.
> - Chặn thực thi PHP trong thư mục `wp-content/uploads` bằng Rewrite Rules trực tiếp trên Virtual Host của OpenLiteSpeed.
> - *Cập nhật: 11/2026*

## Bảo vệ Secrets và `wp-config.php` trên OpenLiteSpeed

Thay vì lưu trực tiếp thông tin kết nối MariaDB trong `/var/www/site/public_html/wp-config.php`, hãy tạo một file `/etc/wp-secrets/site.php` nằm ngoài thư mục webroot, phân quyền chỉ cho user chạy LSPHP (thường là `nobody` hoặc `www-data`) đọc:

```bash
sudo mkdir -p /etc/wp-secrets
sudo chown root:www-data /etc/wp-secrets
sudo chmod 750 /etc/wp-secrets
```

Nội dung `/etc/wp-secrets/site.php`:

```php
<?php
define('DB_NAME', 'wp_prod_db');
define('DB_USER', 'wp_prod_user');
define('DB_PASSWORD', 'MatKhauManh2026!@#');
define('DB_HOST', '127.0.0.1');
```

Trong `wp-config.php`, bạn chỉ cần gọi `require_once '/etc/wp-secrets/site.php';`. Cách làm này ngăn chặn 100% rủi ro lộ mật khẩu DB ngay cả khi xảy ra lỗi đọc file tĩnh hoặc backup nhầm thư mục `public_html`. Đồng thời, trong phần **Rewrite Rules** của OpenLiteSpeed Virtual Host, thêm luật chặn truy cập trực tiếp file cấu hình và chạy PHP trong `uploads`:

```apache
RewriteRule ^wp-content/uploads/.*\.php$ - [F,L]
RewriteRule ^wp-config\.php$ - [F,L]
```

## Cài đặt và tự động gia hạn SSL Let's Encrypt cho OpenLiteSpeed

OpenLiteSpeed không dùng plugin `--nginx` của Certbot mà sử dụng `--webroot`. Chạy lệnh sau để cấp chứng chỉ:

```bash
sudo certbot certonly --webroot -w /var/www/site/public_html \
  -d example.vn -d www.example.vn \
  --deploy-hook "systemctl reload lsws"
```

Sau đó, trong giao diện OpenLiteSpeed WebAdmin (`https://<IP>:7080`) -> **Listeners -> SSL (port 443) -> SSL**, trỏ đường dẫn:
- **Private Key File**: `/etc/letsencrypt/live/example.vn/privkey.pem`
- **Certificate File**: `/etc/letsencrypt/live/example.vn/fullchain.pem`
- **Chained Certificate**: `Yes`

Nhờ `--deploy-hook "systemctl reload lsws"`, mỗi khi Certbot gia hạn chứng chỉ, OpenLiteSpeed sẽ tự động nạp lại SSL mới mà không rớt kết nối. Bạn có thể kiểm tra cấu hình SSL và tốc độ phản hồi bằng [bộ công cụ mạng ThueCloud](https://thuecloud.vn/tools), kết hợp cấu hình IPv6 tĩnh theo bài [hướng dẫn IPv6 trên Rocky Linux 9](https://thuecloud.vn/tren-rocky-linux-9-huong-dan-cau-hinh-ipv6-tinh-va-kiem-tra-dinh-tuyen-mang) và tham khảo thêm [cách sao lưu tự động Windows Server RDS](https://thuecloud.vn/windows-server-remote-desktop-services-cach-sao-luu-tu-dong-va-khoi-phuc-khi-loi) nếu doanh nghiệp có hệ thống Windows kế toán đi kèm.

### Bảng checklist bảo mật & tối ưu WordPress trên OpenLiteSpeed

| Hạng mục | Thực hành chưa chuẩn | Thực hành chuẩn Production |
| :--- | :--- | :--- | 
| **Secrets / `wp-config.php`** | Hardcode mật khẩu trong `public_html` | Tách ra `/etc/wp-secrets/` (`chmod 640`), `require_once` |
| **Thực thi PHP trong `uploads`** | Mặc định cho phép nếu lọt shell | Chặn cứng bằng RewriteRule `[F,L]` trong OLS |
| **Gia hạn SSL Let's Encrypt** | Copy thủ công mỗi 3 tháng | Certbot `--webroot` + `--deploy-hook "systemctl reload lsws"` |
| **LSCache & Object Cache** | Không bật cache | Bật Page Cache + Redis Object Cache cục bộ |

> **Tăng tốc WordPress vượt trội trên KVM Enterprise NVMe tại ThueCloud.Vn:**
> Ổ cứng NVMe tốc độ cao tại `vn-hn` giúp OpenLiteSpeed và MariaDB phản hồi tức thì. Cam kết **SLA 99,9%**, **VAT 0%**, **hoàn tiền 07 ngày**. Xem [bảng giá](https://thuecloud.vn/pricing): **VPS VN 1** (`45.000đ`/`60.000đ`), **VPS VN 2** (`78.000đ`/`90.000đ`), **VPS VN 3** (`139.000đ`/`170.000đ`).

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

### Tại sao sau khi sửa cấu hình trên OpenLiteSpeed WebAdmin hoặc file .htaccess lại chưa có hiệu lực?
OpenLiteSpeed đọc `.htaccess` tại thời điểm khởi động để tăng hiệu năng. Sau khi chỉnh sửa `.htaccess` hoặc cài plugin tạo rule mới (như LSCache), bạn cần nhấn nút **Graceful Restart** trong WebAdmin hoặc chạy `systemctl reload lsws`.

### Làm sao để dùng HTTPS nhưng không bị lỗi Mixed Content trong WordPress?
Sau khi cài SSL thành công, bạn vào **WordPress Admin -> Settings -> General**, đổi cả hai ô *WordPress Address (URL)* và *Site Address (URL)* từ `http://` sang `https://`, sau đó xóa toàn bộ cache của LSCache.

### Gói VPS nào của ThueCloud phù hợp để chạy WordPress + OpenLiteSpeed + WooCommerce?
Với blog/landing page thông thường, **VPS VN 1** (`45.000đ`/`60.000đ`) đã chạy rất mượt nhờ LSCache. Nếu chạy WooCommerce nhiều sản phẩm và plugin, nên chọn **VPS VN 2** (`78.000đ`/`90.000đ`) hoặc **VPS VN 3** (`139.000đ`/`170.000đ`).

## References / Sources

- https://docs.openlitespeed.org/
- https://developer.wordpress.org/advanced-administration/security/hardening/

---

## 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)
