由于某些需要我們重新申請ssl證書,x-ui自動化腳本不能強制更新,根據x-ui倉庫源碼:
https://github.com/vaxilu/x-ui/blob/main/x-ui.sh
在申請ssl證書的地方稍作修改,得到,運行下面的腳本就可以重新申請ssl證書,不過建議使用global key和origin key的方式更安全,這里我就不改了,還是按照global key和cf郵箱的方式
#!/bin/bashRED='\033[31m'
GREEN='\033[32m'
YELLOW='\033[33m'
BLUE='\033[34m'
RESET='\033[0m'# 日志函數
LOGD() { echo -e "${BLUE}[DEBUG] $* ${RESET}"; }
LOGI() { echo -e "${GREEN}[INFO] $* ${RESET}"; }
LOGE() { echo -e "${RED}[ERROR] $* ${RESET}"; }confirm() {local prompt="$1 (默認: $2) "local default="$2"read -p "$prompt" answeranswer=${answer:-$default}[[ $answer =~ ^[Yy]$ ]] && return 0 || return 1
}echo -e "\n${YELLOW}****** 使用說明 ******${RESET}"
LOGI "該腳本將使用 Acme 腳本申請證書,使用時需保證:"
LOGI "1. 知曉 Cloudflare 注冊郵箱"
LOGI "2. 知曉 Cloudflare Global API Key"
LOGI "3. 域名已通過 Cloudflare 解析到當前服務器"
LOGI "4. 證書默認安裝路徑為 /root/cert 目錄"confirm "我已確認以上內容 [y/n]" "y" || { echo -e "${RED}用戶取消操作,退出腳本${RESET}"; exit 1; }cd ~ || { LOGE "無法進入用戶目錄"; exit 1; }# 安裝 acme.sh
LOGI "正在安裝 Acme 腳本..."
curl https://get.acme.sh | sh
if [ $? -ne 0 ]; thenLOGE "安裝 acme.sh 失敗!"exit 1
fiCF_Domain=""
CF_GlobalKey=""
CF_AccountEmail=""
certPath="/root/cert"# 清理并創建證書目錄
LOGI "設置證書目錄: $certPath"
rm -rf "$certPath" 2>/dev/null
mkdir -p "$certPath" || { LOGE "創建目錄失敗!"; exit 1; }LOGD "請輸入域名(如 example.com):"
read -p "Input your domain here: " CF_Domain
LOGD "你的域名設置為: ${CF_Domain}"LOGD "請輸入 Cloudflare Global API Key:"
read -p "Input your key here: " CF_GlobalKey
LOGD "你的 API 密鑰為: ${CF_GlobalKey}"LOGD "請輸入 Cloudflare 注冊郵箱:"
read -p "Input your email here: " CF_AccountEmail
LOGD "你的注冊郵箱為: ${CF_AccountEmail}"# 設置默認 CA
LOGI "配置默認證書頒發機構為 Let's Encrypt..."
~/.acme.sh/acme.sh --set-default-ca --server letsencrypt || { LOGE "配置 CA 失敗!"; exit 1; }export CF_Key="${CF_GlobalKey}"
export CF_Email="${CF_AccountEmail}"# 申請證書
LOGI "正在簽發證書(域名: ${CF_Domain})..."
~/.acme.sh/acme.sh --issue --dns dns_cf -d "${CF_Domain}" -d "*.${CF_Domain}" --log --force
if [ $? -ne 0 ]; thenLOGE "證書簽發失敗!"exit 1
fi# 安裝證書
LOGI "正在安裝證書到 $certPath ..."
~/.acme.sh/acme.sh --install-cert -d "${CF_Domain}" -d "*.${CF_Domain}" \--ca-file "${certPath}/ca.cer" \--cert-file "${certPath}/${CF_Domain}.cer" \--key-file "${certPath}/${CF_Domain}.key" \--fullchain-file "${certPath}/fullchain.cer"if [ $? -ne 0 ]; thenLOGE "證書安裝失敗!"exit 1
fi# 設置自動更新
LOGI "啟用自動更新..."
~/.acme.sh/acme.sh --upgrade --auto-upgrade || { LOGE "自動更新設置失敗!"; exit 1; }# 設置權限
LOGI "設置證書文件權限..."
chmod 600 "${certPath}"/*.cer "${certPath}"/*.key 2>/dev/null
chmod 700 "$certPath"LOGI "${GREEN}證書申請成功!${RESET}"
echo -e "\n${YELLOW}證書文件信息:${RESET}"
ls -lah "$certPath"exit 0