#!/bin/bash # 备份并覆盖所有.conf配置文件 for conf in *.conf; do cp "/etc/nginx/$conf" "/etc/nginx/${conf}.bak" 2>/dev/null || true cp "$conf" /etc/nginx/ done # 测试并重载配置 if nginx -t; then systemctl reload nginx echo "配置已生效,HTTPS已启用" else echo "配置测试失败,正在恢复所有备份" for conf in *.conf; do mv -f "/etc/nginx/${conf}.bak" "/etc/nginx/$conf" 2>/dev/null || true done fi