S-UI HTTPS 配置完整教程
目录
1. 前提条件检查
Section titled “1. 前提条件检查”在开始之前,请逐项确认以下条件。
1.1 确认 s-ui 正在运行
Section titled “1.1 确认 s-ui 正在运行”s-ui# 查看底部状态行,确认显示:# s-ui state: Running1.2 记录当前面板端口和订阅端口
Section titled “1.2 记录当前面板端口和订阅端口”s-ui# 选择 10. View Panel Settings# 记录以下信息:# Panel Port(面板端口,默认 2095)# Subscription Port(订阅端口,默认 2096)# Web Base Path(面板路径,默认 /)# Subscription Path(订阅路径)1.3 确认 80 端口空闲
Section titled “1.3 确认 80 端口空闲”ss -tlnp | grep :80# 无输出 = 80 端口空闲,可以继续# 有输出 = 有程序占用,需要先停止(见常见问题)1.4 确认域名已准备好
Section titled “1.4 确认域名已准备好”你需要一个解析到本服务器 IP 的域名,例如 panel.yourdomain.com。
如果还没有解析记录,请先完成下一节的 Cloudflare 配置。
2. Cloudflare DNS 配置
Section titled “2. Cloudflare DNS 配置”2.1 登录 Cloudflare 控制台
Section titled “2.1 登录 Cloudflare 控制台”访问 https://dash.cloudflare.com,选择你的域名。
2.2 添加 A 记录
Section titled “2.2 添加 A 记录”进入 DNS → Records,点击 Add record:
| 字段 | 填写内容 |
|---|---|
| Type | A |
| Name | panel(即子域名部分,最终结果为 panel.yourdomain.com) |
| IPv4 address | 你的服务器公网 IP |
| Proxy status | 关闭(灰色云朵 DNS only) ⚠️ |
| TTL | Auto |
重要:必须关闭 Cloudflare 代理(橙色云朵→灰色云朵)
申请证书时,acme.sh 需要直接连接到服务器的 80 端口进行 HTTP 验证。
开启代理后 Cloudflare 会拦截连接,导致证书申请失败。
证书申请成功后,可以根据需要再决定是否开启代理。
2.3 等待 DNS 生效
Section titled “2.3 等待 DNS 生效”DNS 记录通常在 1~5 分钟内生效。可以用以下命令验证:
# 在服务器上执行ping panel.yourdomain.com# 确认解析到的 IP 就是本服务器的 IP或者使用:
nslookup panel.yourdomain.com# 查看 Address 字段是否为服务器 IP3. 服务器防火墙配置
Section titled “3. 服务器防火墙配置”申请证书需要 80 端口可以从外部访问,同时面板和订阅端口也需要放行。
# 放行 80 端口(证书申请用)ufw allow 80/tcp
# 放行面板端口(替换 2095 为你的实际端口)ufw allow 2095/tcp
# 放行订阅端口(替换 2096 为你的实际端口)ufw allow 2096/tcp
# 应用规则ufw reload
# 查看当前规则确认ufw status如果使用云服务商的安全组(如腾讯云、阿里云、AWS):
还需要在云控制台的「安全组」或「防火墙」中添加入站规则,放行 80、2095、2096 端口。仅配置 ufw 还不够。
4. 申请 SSL 证书(s-ui 内置方式)
Section titled “4. 申请 SSL 证书(s-ui 内置方式)”s-ui 内置了完整的 SSL 证书申请功能,底层使用 acme.sh 调用 Let’s Encrypt / ZeroSSL,全程交互式操作,无需手动安装任何额外工具。
4.1 进入 SSL 证书管理菜单
Section titled “4.1 进入 SSL 证书管理菜单”s-ui在菜单中输入 19,回车:
19. SSL Certificate Management进入子菜单后,选择 1(Get SSL):
1. Get SSL2. Revoke3. Force Renew4. Self-signed CertificateChoose an option: 14.2 按提示输入域名
Section titled “4.2 按提示输入域名”脚本会提示你输入域名:
Please enter your domain name to apply for the certificate:> panel.yourdomain.com输入你的完整子域名,回车确认。
4.3 等待申请过程完成
Section titled “4.3 等待申请过程完成”脚本会自动执行以下步骤,过程大约需要 30~60 秒:
[INFO] Checking for acme.sh...[INFO] Installing acme.sh... ← 首次运行时自动安装 acme.sh[INFO] Applying for SSL certificate...[INFO] Verifying domain ownership... ← 临时启动 HTTP 服务监听 80 端口[INFO] Certificate issued successfully![INFO] Installing certificate to /root/cert/[INFO] Setting up auto-renewal... ← 自动配置 cron 定时续期4.4 确认证书文件位置
Section titled “4.4 确认证书文件位置”申请成功后,证书文件默认安装在 /root/cert/ 目录下:
ls -la /root/cert/panel.yourdomain.com/预期输出(文件名可能略有不同):
fullchain.cer ← 完整证书链,面板配置时使用此文件panel.yourdomain.com.key ← 私钥文件,面板配置时使用此文件panel.yourdomain.com.cer ← 单域名证书(备用)ca.cer ← CA 中间证书(备用)记录这两个路径,下一步需要用到:
- 证书文件:
/root/cert/panel.yourdomain.com/fullchain.cer- 私钥文件:
/root/cert/panel.yourdomain.com/panel.yourdomain.com.key
5. 在面板中配置证书路径
Section titled “5. 在面板中配置证书路径”证书申请完成后,需要在 s-ui 面板设置中告诉它证书在哪里。有两种方式:命令行和网页面板,任选其一。
方式 A:通过命令行配置(推荐,当前面板还是 HTTP 时使用)
Section titled “方式 A:通过命令行配置(推荐,当前面板还是 HTTP 时使用)”s-ui# 选择 9. Set Panel settings按照提示,依次设置以下项目(直接回车跳过不需要修改的项):
Enter the panel port (leave blank for existing/default value):> [直接回车,保持默认 2095]
Enter the subscription port (leave blank for existing/default value):> [直接回车,保持默认 2096]
Enter the web base path (leave blank for existing/default value):> [直接回车]
Enter the subscription path (leave blank for existing/default value):> [直接回车]
Enter the certificate file path (leave blank for existing/default value):> /root/cert/panel.yourdomain.com/fullchain.cer
Enter the certificate key file path (leave blank for existing/default value):> /root/cert/panel.yourdomain.com/panel.yourdomain.com.key
Enter the subscription address (leave blank for existing/default value):> https://panel.yourdomain.com方式 B:通过网页面板配置
Section titled “方式 B:通过网页面板配置”如果面板当前可以访问(HTTP 状态),登录后进入:
Settings → Panel Settings,填写:
| 字段 | 填写内容 |
|---|---|
| Certificate File | /root/cert/panel.yourdomain.com/fullchain.cer |
| Certificate Key File | /root/cert/panel.yourdomain.com/panel.yourdomain.com.key |
Settings → Subscription Settings,填写:
| 字段 | 填写内容 |
|---|---|
| Certificate File | /root/cert/panel.yourdomain.com/fullchain.cer |
| Certificate Key File | /root/cert/panel.yourdomain.com/panel.yourdomain.com.key |
| Subscription Address | https://panel.yourdomain.com |
5.1 重启 s-ui 使配置生效
Section titled “5.1 重启 s-ui 使配置生效”s-ui# 选择 13. S-UI Restart6. 验证 HTTPS 是否生效
Section titled “6. 验证 HTTPS 是否生效”6.1 验证面板 HTTPS 访问
Section titled “6.1 验证面板 HTTPS 访问”在浏览器中访问(替换为你的域名和端口):
https://panel.yourdomain.com:2095预期结果:
- 浏览器地址栏显示 🔒 锁标志
- 能正常看到 s-ui 登录页面
- 无证书警告
6.2 验证订阅链接 HTTPS
Section titled “6.2 验证订阅链接 HTTPS”订阅链接格式为:
https://panel.yourdomain.com:2096/你的订阅路径/你的订阅Token具体的订阅路径和 Token 在面板 Clients 页面查看。
可以用 curl 测试订阅链接是否可以正常返回内容:
curl -v https://panel.yourdomain.com:2096/你的订阅路径/你的Token# 如果返回节点配置信息,说明 HTTPS 订阅正常工作6.3 验证证书信息
Section titled “6.3 验证证书信息”# 查看证书的有效期和颁发机构openssl s_client -connect panel.yourdomain.com:2095 \ -servername panel.yourdomain.com 2>/dev/null \ | openssl x509 -noout -dates -issuer预期输出类似:
notBefore=Apr 1 00:00:00 2026 GMTnotAfter=Jun 30 00:00:00 2026 GMTissuer=C=US, O=Let's Encrypt, CN=R107. 证书续期说明
Section titled “7. 证书续期说明”Let’s Encrypt 证书有效期为 90 天。acme.sh 在安装时会自动创建 cron 定时任务,每天检查一次,到期前约 30 天自动续期,并在续期后自动重启 s-ui 使新证书生效,无需人工干预。
7.1 查看 cron 任务
Section titled “7.1 查看 cron 任务”crontab -l# 应该能看到类似以下的 acme.sh 定时任务:# 56 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null7.2 手动测试续期(可选)
Section titled “7.2 手动测试续期(可选)”# 测试续期流程(不会真正续期,仅模拟)~/.acme.sh/acme.sh --renew -d panel.yourdomain.com --dry-run
# 强制立即续期(用于测试或证书出问题时)# 也可以通过 s-ui 菜单:19 → 3. Force Renew~/.acme.sh/acme.sh --renew -d panel.yourdomain.com --force7.3 查看证书当前有效期
Section titled “7.3 查看证书当前有效期”~/.acme.sh/acme.sh --list8. 常见问题排查
Section titled “8. 常见问题排查”Q1:证书申请失败,提示 80 端口被占用
Section titled “Q1:证书申请失败,提示 80 端口被占用”排查:
ss -tlnp | grep :80# 查看输出中 LISTEN 状态的进程名解决: 临时停止占用 80 端口的服务,申请完成后再启动。
# 如果是 nginxsystemctl stop nginx
# 申请证书后再恢复systemctl start nginxQ2:证书申请失败,提示域名无法验证
Section titled “Q2:证书申请失败,提示域名无法验证”可能原因:
- Cloudflare 代理(橙色云朵)未关闭
- DNS 记录还未生效
- 云服务商安全组未放行 80 端口
排查步骤:
# 1. 确认 DNS 解析正确curl -v http://panel.yourdomain.com# 如果连接被拒绝或超时,说明 80 端口网络不通
# 2. 在本地测试ping panel.yourdomain.com# 确认 IP 是服务器 IP,不是 Cloudflare 的 IP(如 104.x.x.x)Q3:配置证书后面板无法访问
Section titled “Q3:配置证书后面板无法访问”排查:
# 检查 s-ui 是否正常运行systemctl status s-ui
# 查看日志s-ui # 选 15. S-UI Check Logs
# 确认证书文件存在且可读ls -la /root/cert/panel.yourdomain.com/常见原因: 证书路径填写有误(注意文件名大小写),或私钥文件权限不足。
# 确保 root 可以读取chmod 600 /root/cert/panel.yourdomain.com/panel.yourdomain.com.keychmod 644 /root/cert/panel.yourdomain.com/fullchain.cerQ4:浏览器显示证书警告「NET::ERR_CERT_AUTHORITY_INVALID」
Section titled “Q4:浏览器显示证书警告「NET::ERR_CERT_AUTHORITY_INVALID」”可能原因: 用了自签名证书(选项 4)而非正式证书(选项 1)。
解决: 重新执行第 4 节,使用 19 → 1. Get SSL 申请正式证书。
Q5:客户端导入订阅后显示「TLS 握手失败」
Section titled “Q5:客户端导入订阅后显示「TLS 握手失败」”排查:
- 确认订阅链接使用
https://前缀 - 确认面板 Subscription Settings 中的 Subscription Address 填写了
https://panel.yourdomain.com(不含端口号,端口在客户端订阅 URL 中指定) - 重新在客户端复制订阅链接并更新
Q6:证书申请成功,但访问时显示「端口不可达」
Section titled “Q6:证书申请成功,但访问时显示「端口不可达」”排查:
# 确认 s-ui 在监听预期端口ss -tlnp | grep sui
# 确认防火墙已放行ufw status | grep -E "2095|2096"附录:关键文件和路径速查
Section titled “附录:关键文件和路径速查”| 内容 | 路径 |
|---|---|
| 证书文件(fullchain) | /root/cert/panel.yourdomain.com/fullchain.cer |
| 私钥文件 | /root/cert/panel.yourdomain.com/panel.yourdomain.com.key |
| acme.sh 程序 | ~/.acme.sh/acme.sh |
| acme.sh 证书原始目录 | ~/.acme.sh/panel.yourdomain.com/ |
| s-ui 管理脚本 | /usr/bin/s-ui |
| s-ui 数据库 | /usr/local/s-ui/db/ |
附录:完成后的访问地址
Section titled “附录:完成后的访问地址”| 用途 | 地址 |
|---|---|
| 面板登录 | https://panel.yourdomain.com:2095 |
| 订阅链接 | https://panel.yourdomain.com:2096/<订阅路径>/<Token> |
将
panel.yourdomain.com、2095、2096替换为你的实际域名和端口。