Skip to content

S-UI HTTPS 配置完整教程

目录

  1. 前提条件检查
  2. Cloudflare DNS 配置
  3. 服务器防火墙配置
  4. 申请 SSL 证书(s-ui 内置方式)
  5. 在面板中配置证书路径
  6. 验证 HTTPS 是否生效
  7. 证书续期说明
  8. 常见问题排查

在开始之前,请逐项确认以下条件。

Terminal window
s-ui
# 查看底部状态行,确认显示:
# s-ui state: Running

1.2 记录当前面板端口和订阅端口

Section titled “1.2 记录当前面板端口和订阅端口”
Terminal window
s-ui
# 选择 10. View Panel Settings
# 记录以下信息:
# Panel Port(面板端口,默认 2095)
# Subscription Port(订阅端口,默认 2096)
# Web Base Path(面板路径,默认 /)
# Subscription Path(订阅路径)
Terminal window
ss -tlnp | grep :80
# 无输出 = 80 端口空闲,可以继续
# 有输出 = 有程序占用,需要先停止(见常见问题)

你需要一个解析到本服务器 IP 的域名,例如 panel.yourdomain.com
如果还没有解析记录,请先完成下一节的 Cloudflare 配置。


访问 https://dash.cloudflare.com,选择你的域名。

进入 DNS → Records,点击 Add record

字段填写内容
TypeA
Namepanel(即子域名部分,最终结果为 panel.yourdomain.com
IPv4 address你的服务器公网 IP
Proxy status关闭(灰色云朵 DNS only) ⚠️
TTLAuto

重要:必须关闭 Cloudflare 代理(橙色云朵→灰色云朵)
申请证书时,acme.sh 需要直接连接到服务器的 80 端口进行 HTTP 验证。
开启代理后 Cloudflare 会拦截连接,导致证书申请失败。
证书申请成功后,可以根据需要再决定是否开启代理。

DNS 记录通常在 1~5 分钟内生效。可以用以下命令验证:

Terminal window
# 在服务器上执行
ping panel.yourdomain.com
# 确认解析到的 IP 就是本服务器的 IP

或者使用:

Terminal window
nslookup panel.yourdomain.com
# 查看 Address 字段是否为服务器 IP

申请证书需要 80 端口可以从外部访问,同时面板和订阅端口也需要放行。

Terminal window
# 放行 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,全程交互式操作,无需手动安装任何额外工具。

Terminal window
s-ui

在菜单中输入 19,回车:

19. SSL Certificate Management

进入子菜单后,选择 1(Get SSL):

1. Get SSL
2. Revoke
3. Force Renew
4. Self-signed Certificate
Choose an option: 1

脚本会提示你输入域名:

Please enter your domain name to apply for the certificate:
> panel.yourdomain.com

输入你的完整子域名,回车确认。

脚本会自动执行以下步骤,过程大约需要 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 定时续期

申请成功后,证书文件默认安装在 /root/cert/ 目录下:

Terminal window
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

证书申请完成后,需要在 s-ui 面板设置中告诉它证书在哪里。有两种方式:命令行和网页面板,任选其一。

方式 A:通过命令行配置(推荐,当前面板还是 HTTP 时使用)

Section titled “方式 A:通过命令行配置(推荐,当前面板还是 HTTP 时使用)”
Terminal window
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

如果面板当前可以访问(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 Addresshttps://panel.yourdomain.com
Terminal window
s-ui
# 选择 13. S-UI Restart

在浏览器中访问(替换为你的域名和端口):

https://panel.yourdomain.com:2095

预期结果:

  • 浏览器地址栏显示 🔒 锁标志
  • 能正常看到 s-ui 登录页面
  • 无证书警告

订阅链接格式为:

https://panel.yourdomain.com:2096/你的订阅路径/你的订阅Token

具体的订阅路径和 Token 在面板 Clients 页面查看。

可以用 curl 测试订阅链接是否可以正常返回内容:

Terminal window
curl -v https://panel.yourdomain.com:2096/你的订阅路径/你的Token
# 如果返回节点配置信息,说明 HTTPS 订阅正常工作
Terminal window
# 查看证书的有效期和颁发机构
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 GMT
notAfter=Jun 30 00:00:00 2026 GMT
issuer=C=US, O=Let's Encrypt, CN=R10

Let’s Encrypt 证书有效期为 90 天。acme.sh 在安装时会自动创建 cron 定时任务,每天检查一次,到期前约 30 天自动续期,并在续期后自动重启 s-ui 使新证书生效,无需人工干预

Terminal window
crontab -l
# 应该能看到类似以下的 acme.sh 定时任务:
# 56 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null
Terminal window
# 测试续期流程(不会真正续期,仅模拟)
~/.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 --force
Terminal window
~/.acme.sh/acme.sh --list

Q1:证书申请失败,提示 80 端口被占用

Section titled “Q1:证书申请失败,提示 80 端口被占用”

排查:

Terminal window
ss -tlnp | grep :80
# 查看输出中 LISTEN 状态的进程名

解决: 临时停止占用 80 端口的服务,申请完成后再启动。

Terminal window
# 如果是 nginx
systemctl stop nginx
# 申请证书后再恢复
systemctl start nginx

Q2:证书申请失败,提示域名无法验证

Section titled “Q2:证书申请失败,提示域名无法验证”

可能原因:

  • Cloudflare 代理(橙色云朵)未关闭
  • DNS 记录还未生效
  • 云服务商安全组未放行 80 端口

排查步骤:

Terminal window
# 1. 确认 DNS 解析正确
curl -v http://panel.yourdomain.com
# 如果连接被拒绝或超时,说明 80 端口网络不通
# 2. 在本地测试
ping panel.yourdomain.com
# 确认 IP 是服务器 IP,不是 Cloudflare 的 IP(如 104.x.x.x)

排查:

Terminal window
# 检查 s-ui 是否正常运行
systemctl status s-ui
# 查看日志
s-ui # 选 15. S-UI Check Logs
# 确认证书文件存在且可读
ls -la /root/cert/panel.yourdomain.com/

常见原因: 证书路径填写有误(注意文件名大小写),或私钥文件权限不足。

Terminal window
# 确保 root 可以读取
chmod 600 /root/cert/panel.yourdomain.com/panel.yourdomain.com.key
chmod 644 /root/cert/panel.yourdomain.com/fullchain.cer

Q4:浏览器显示证书警告「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:证书申请成功,但访问时显示「端口不可达」”

排查:

Terminal window
# 确认 s-ui 在监听预期端口
ss -tlnp | grep sui
# 确认防火墙已放行
ufw status | grep -E "2095|2096"

内容路径
证书文件(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/
用途地址
面板登录https://panel.yourdomain.com:2095
订阅链接https://panel.yourdomain.com:2096/<订阅路径>/<Token>

panel.yourdomain.com20952096 替换为你的实际域名和端口。