WHMCS 作為主流主機計費系統,安全配置直接關係業務數據安全。本文提供生產環境級加固清單。
rm -rf /path/to/whmcs/install
chmod 640 /path/to/whmcs/configuration.php
chown nginx:nginx /path/to/whmcs/configuration.php # 根據 Web 服務器用戶調整
# 假設 Web 根目錄 /home/user/public_html,WHMCS 安裝於 /home/user/public_html/whmcs
mkdir -p /home/user/whmcs_data
mv /home/user/public_html/whmcs/attachments /home/user/whmcs_data/
mv /home/user/public_html/whmcs/downloads /home/user/whmcs_data/
mv /home/user/public_html/whmcs/templates_c /home/user/whmcs_data/
編輯 configuration.php 更新路徑:
$templates_compiledir = "/home/user/whmcs_data/templates_c/";
$attachments_dir = "/home/user/whmcs_data/attachments/";
$downloads_dir = "/home/user/whmcs_data/downloads/";
mv /home/user/public_html/whmcs/admin /home/user/public_html/whmcs/mysecureadmin123
編輯 configuration.php:
$customadminpath = "mysecureadmin123";
更新 Cron 任務路徑:
php -q /home/user/public_html/whmcs/mysecureadmin123/cron.php
Nginx 配置片段:
server {
listen 443 ssl http2;
server_name whmcs.example.com;
# SSL 證書配置...
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
add_header X-XSS-Protection "1; mode=block";
add_header Referrer-Policy "strict-origin-when-cross-origin";
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline';";
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# 禁止訪問敏感文件
location ~* \.(php|inc|sql|bak|log)$ {
deny all;
}
}
/var/log/whmcs/ 異常登錄嘗試[whmcs-auth]
filter = whmcs-auth
action = iptables-multiport[name=whmcs, port="http,https"]
logpath = /var/log/whmcs/access.log
maxretry = 5
bantime = 3600
# 安裝 AIDE
yum install -y aide
aide --init
mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
# 定時任務每日檢查
0 3 * * * /usr/sbin/aide --check | mail -s "AIDE Report" admin@example.com
核心原則:最小權限、目錄隔離、隱藏入口、強制加密、持續監控。按清單逐項落地,可將 WHMCS 攻擊面降至最低。