diff --git a/core/web_api.py b/core/web_api.py
index f29ecea..a716d4d 100644
--- a/core/web_api.py
+++ b/core/web_api.py
@@ -632,9 +632,12 @@ def web_ssl_config():
ok = save_web_config(updates)
if ok:
+ # 在后台线程中延迟退出,让进程重启以加载新配置(systemd Restart=always 会自动拉起)
+ threading.Thread(target=lambda: (time.sleep(1.5), os._exit(0)), daemon=True).start()
return jsonify({
"success": True,
- "message": "SSL 配置已保存,重启服务后生效",
+ "message": "SSL 配置已保存,服务自动重启中…",
+ "restarting": True,
**updates
})
return jsonify({"success": False, "error": "写入配置文件失败"}), 500
diff --git a/ui/templates/settings.html b/ui/templates/settings.html
index c7fa014..5e8fdd2 100644
--- a/ui/templates/settings.html
+++ b/ui/templates/settings.html
@@ -700,14 +700,24 @@
if (data.success) {
document.getElementById('sslStatus').innerHTML = ' ' + (data.message || '配置已保存');
showSuccess('HTTPS 配置已保存');
+ if (data.restarting) {
+ btn.textContent = '服务重启中… 页面将自动刷新';
+ btn.style.background = 'var(--warning-color, #f59e0b)';
+ // 等待服务重启后自动刷新页面
+ setTimeout(() => { window.location.reload(); }, 4000);
+ }
} else {
document.getElementById('sslStatus').innerHTML = ' ' + (data.error || '保存失败');
}
} catch (e) {
- document.getElementById('sslStatus').innerHTML = ' 网络错误';
+ // 服务重启时连接会断开,这是预期行为
+ document.getElementById('sslStatus').innerHTML = ' 服务正在重启… 页面将自动刷新';
+ btn.textContent = '服务重启中…';
+ btn.style.background = 'var(--warning-color, #f59e0b)';
+ setTimeout(() => { window.location.reload(); }, 4000);
} finally {
btn.disabled = false;
- btn.textContent = '保 存 HTTPS 配 置';
+ // 不重置按钮文案,保持重启中的视觉状态
}
});