feat: 悬挂ICP备案号,修复验证码、500登录、/admin Failed to Fetch,优化首页编辑器100%全屏平铺
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import paramiko
|
||||
import sys
|
||||
|
||||
# 强制配置标准输出为 UTF-8 编码,防止 Windows 控制台因 GBK 导致 Unicode 编码报错
|
||||
if hasattr(sys.stdout, 'reconfigure'):
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
|
||||
# 远程服务器配置
|
||||
HOST = "175.178.162.18"
|
||||
PORT = 22
|
||||
USERNAME = "root"
|
||||
PASSWORD = "sp-cc123"
|
||||
|
||||
def execute_remote_cmd(ssh, cmd):
|
||||
print(f"[CMD] 远程执行: {cmd}")
|
||||
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||
|
||||
# 阻塞式读取以实时输出日志
|
||||
while not stdout.channel.exit_status_ready():
|
||||
if stdout.channel.recv_ready():
|
||||
out = stdout.channel.recv(1024).decode('utf-8', errors='ignore')
|
||||
sys.stdout.write(out)
|
||||
sys.stdout.flush()
|
||||
if stderr.channel.recv_stderr_ready():
|
||||
err = stderr.channel.recv_stderr(1024).decode('utf-8', errors='ignore')
|
||||
sys.stderr.write(err)
|
||||
sys.stderr.flush()
|
||||
|
||||
# 读取剩余输出
|
||||
out = stdout.read().decode('utf-8', errors='ignore')
|
||||
err = stderr.read().decode('utf-8', errors='ignore')
|
||||
if out: sys.stdout.write(out)
|
||||
if err: sys.stderr.write(err)
|
||||
|
||||
exit_status = stdout.channel.recv_exit_status()
|
||||
print(f"\n[INFO] 命令结束状态码: {exit_status}\n")
|
||||
return exit_status
|
||||
|
||||
def main():
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
print(f"正在连接远程服务器 {HOST}...")
|
||||
ssh.connect(HOST, port=PORT, username=USERNAME, password=PASSWORD, timeout=10)
|
||||
print("SSH 连接成功!\n")
|
||||
|
||||
# 1. 更新包源并安装 certbot 和 python3-certbot-nginx
|
||||
print("=== [1/2] 正在更新软件源并安装 Certbot & Nginx 插件 ===")
|
||||
cmd_install = "export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get install -y certbot python3-certbot-nginx"
|
||||
status = execute_remote_cmd(ssh, cmd_install)
|
||||
if status != 0:
|
||||
print("[ERROR] 安装 Certbot 失败,请检查服务器网络与 apt 源状态!")
|
||||
ssh.close()
|
||||
sys.exit(1)
|
||||
|
||||
# 2. 运行 certbot
|
||||
print("=== [2/2] 正在通过 Certbot 申请 SSL 证书并配置 Nginx ===")
|
||||
# --nginx 表示自动读写 nginx 配置,-d 指定域名
|
||||
# --non-interactive 表示非交互模式
|
||||
# --agree-tos 表示同意服务条款
|
||||
# -m 指定管理员邮箱
|
||||
# --redirect 表示自动添加 HTTP 301 重定向到 HTTPS 规则
|
||||
cmd_cert = "certbot --nginx -d www.aiformat.cn --non-interactive --agree-tos -m admin@aiformat.cn --redirect"
|
||||
status = execute_remote_cmd(ssh, cmd_cert)
|
||||
if status != 0:
|
||||
print("[ERROR] Certbot 申请证书失败!")
|
||||
print("\n友情提示:此错误通常是由于域名 DNS 解析还未生效引起的。")
|
||||
print("请您进行以下检查:")
|
||||
print("1. 域名 aiformat.cn 是否已经在腾讯云 DNS 控制台中正确添加了 A 记录(解析到 IP 175.178.162.18)。")
|
||||
print("2. 腾讯云安全组中是否已成功放行 80 (HTTP) 和 443 (HTTPS) 端口。")
|
||||
ssh.close()
|
||||
sys.exit(1)
|
||||
|
||||
print("[SUCCESS] HTTPS SSL 证书已成功应用到 Nginx 配置,并已开启自动续期服务!")
|
||||
ssh.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user