Files
common-server-public/nginx/updateConfig.sh
2025-03-09 16:14:12 +08:00

30 lines
944 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 创建 conf.d 目录(如果不存在)
mkdir -p /etc/nginx/conf.d
# 备份并覆盖 nginx.conf 文件
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
cp nginx.conf /etc/nginx/
# 备份并覆盖 conf.d 目录下的所有 .conf 文件
for conf in conf.d/*.conf; do
filename=$(basename "$conf")
cp "/etc/nginx/conf.d/$filename" "/etc/nginx/conf.d/${filename}.bak" 2>/dev/null || true
cp "$conf" /etc/nginx/conf.d/
done
# 测试并重载配置
if nginx -t; then
systemctl reload nginx
echo "配置已生效HTTPS已启用"
else
echo "配置测试失败,已恢复备份"
# 恢复 nginx.conf 备份
cp /etc/nginx/nginx.conf.bak /etc/nginx/nginx.conf
# 恢复 conf.d 目录下的所有 .conf 文件备份
for conf in conf.d/*.conf; do
filename=$(basename "$conf")
mv -f "/etc/nginx/conf.d/${filename}.bak" "/etc/nginx/conf.d/$filename" 2>/dev/null || true
done
fi