Skip to content

公网 HTTPS 证书获取 / 更新 / 部署手册

生成日期:2026-07-30
适用环境:演示公网机 182.92.106.252 / 域名 ruoyioffice.com
关联配置:../vben/nginx/ruoyi-office.conflocations-ruoyi-office.inc(见 Nginx 配置说明

1. 架构与目录约定

路径 / 说明
公网机182.92.106.252(nginx Docker 容器名 nginx
域名主域名 ruoyioffice.comwww 可选(当前 DNS 无 A 记录时勿加入证书 SAN)
策略(首期)HTTP + HTTPS 双开,不强制 301
证书颁发Let’s Encrypt(certbot webroot,不停机)
宿主机证书/data/nginx/ssl/ruoyioffice.com/ → 链到 /etc/letsencrypt/live/ruoyioffice.com/
容器内证书/etc/nginx/ssl/ruoyioffice.com/{fullchain,privkey}.pem
ACME webroot宿主机 /data/nginx/html/acme/ → 容器 /usr/share/nginx/html/acme/
站点 conf/data/nginx/conf/conf.d/ruoyi-office.conf
公共 location/data/nginx/conf/conf.d/locations-ruoyi-office.inc(80/443 共用)
续期脚本本目录 renew-and-reload.sh(拷到公网机 /data/nginx/bin/
text
Browser
  ├─ https://ruoyioffice.com/*   → nginx :80
  └─ https://ruoyioffice.com/*  → nginx :443  (ssl_certificate from /data/nginx/ssl)
Let’s Encrypt HTTP-01 → /.well-known/acme-challenge/ on :80 (webroot)
certbot renew → 写 live/ → reload nginx 容器

2. 首次签发步骤

2.1 前置检查

bash
# DNS
getent hosts ruoyioffice.com www.ruoyioffice.com
# 应解析到 182.92.106.252

# 端口(安全组需放行 80/443)
ss -lntp | grep -E ':80|:443'

2.2 目录

bash
mkdir -p /data/nginx/ssl /data/nginx/html/acme/.well-known/acme-challenge /data/nginx/bin

2.3 nginx 容器增加 ssl 挂载

原挂载含 conf / html / logs。需额外:

text
/data/nginx/ssl -> /etc/nginx/ssl

示例(保留原有 bind,按实际 docker inspect nginx 调整):

bash
docker stop nginx
docker rm nginx
docker run -d --name nginx --restart unless-stopped \
  -p 80:80 -p 443:443 \
  -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro \
  -v /data/nginx/conf/conf.d:/etc/nginx/conf.d:ro \
  -v /data/nginx/html:/usr/share/nginx/html:ro \
  -v /data/nginx/logs:/var/log/nginx \
  -v /data/nginx/ssl:/etc/nginx/ssl:ro \
  nginx:latest

若线上还有 network_mode / 其它 volume,以 inspect 为准合并,勿丢挂载。

2.4 配置 ACME + server_name(仅 80 先生效)

  1. 备份:cp -a /data/nginx/conf/conf.d/ruoyi-office.conf /data/nginx/conf/conf.d/ruoyi-office.conf.bak.https-$(date +%Y%m%d%H%M%S)
  2. server_name 含:ruoyioffice.com www.ruoyioffice.com 182.92.106.252 _;
  3. 在业务 location 之前增加:
nginx
location ^~ /.well-known/acme-challenge/ {
    root /usr/share/nginx/html/acme;
    default_type text/plain;
}
  1. docker exec nginx nginx -t && docker exec nginx nginx -s reload

2.5 安装 certbot 并签发

CentOS 7:

bash
yum install -y epel-release
yum install -y certbot

签发(运维邮箱可改)。仅在 www 已解析到本机时再加 -d www.ruoyioffice.com,否则 Let’s Encrypt 校验失败:

bash
# 当前线上:仅 apex(www 尚无 A 记录)
certbot certonly --webroot -w /data/nginx/html/acme \
  -d ruoyioffice.com \
  --email admin@ruoyioffice.com --agree-tos --non-interactive --no-eff-email

# www 就绪后扩容 SAN:
# certbot certonly --webroot -w /data/nginx/html/acme \
#   -d ruoyioffice.com -d www.ruoyioffice.com \
#   --expand --email admin@ruoyioffice.com --agree-tos --non-interactive --no-eff-email

挂到 nginx 使用目录:

bash
mkdir -p /data/nginx/ssl/ruoyioffice.com
# 推荐:拷贝实文件(容器只读挂载时无法跟随 /etc/letsencrypt/live 内相对软链)
cp -L /etc/letsencrypt/live/ruoyioffice.com/fullchain.pem /data/nginx/ssl/ruoyioffice.com/
cp -L /etc/letsencrypt/live/ruoyioffice.com/privkey.pem   /data/nginx/ssl/ruoyioffice.com/
chmod 644 /data/nginx/ssl/ruoyioffice.com/fullchain.pem
chmod 600 /data/nginx/ssl/ruoyioffice.com/privkey.pem
docker exec nginx ls -la /etc/nginx/ssl/ruoyioffice.com/

续期脚本 renew-and-reload.sh 会在续期后再次 cp -L 同步并 reload。

2.6 启用 443

ruoyioffice.conf 中增加 listen 443 ssl http2server,与 80 共用 locations-ruoyi-office.inc,证书路径:

nginx
ssl_certificate     /etc/nginx/ssl/ruoyioffice.com/fullchain.pem;
ssl_certificate_key /etc/nginx/ssl/ruoyioffice.com/privkey.pem;
ssl_protocols       TLSv1.2 TLSv1.3;

首期不做 return 301 https://...

bash
docker exec nginx nginx -t && docker exec nginx nginx -s reload

3. nginx / Docker 挂载变更清单

变更说明
宿主机 /data/nginx/ssl证书(或软链)
容器 -v .../ssl:/etc/nginx/ssl:ro必加
locations-ruoyi-office.inc业务 location 单一来源
ruoyi-office.conf仅两个 server(80/443)+ include
ACME location仅需在 80(443 也可 include 同一文件,无害)

4. 续期与 cron

将本仓库脚本拷到公网机:

bash
# 从文档仓或运维机上传
install -m 755 renew-and-reload.sh /data/nginx/bin/renew-and-reload.sh

cron(每天 03:17):

cron
17 3 * * * /data/nginx/bin/renew-and-reload.sh >> /var/log/letsencrypt-renew-nginx.log 2>&1

脚本行为:certbot renew → 若有更新则同步 pem 到 /data/nginx/ssl/...docker exec nginx nginx -s reload

手动试跑: /data/nginx/bin/renew-and-reload.sh

5. 验证清单

bash
curl -sI https://ruoyioffice.com/web | head -5
curl -sIk https://ruoyioffice.com/web | head -10
curl -sIk https://ruoyioffice.com/weather-api/health
echo | openssl s_client -servername ruoyioffice.com -connect ruoyioffice.com:443 2>/dev/null | openssl x509 -noout -dates -subject

期望:HTTP/HTTPS 均 200;证书 CN/SAN 含 ruoyioffice.com;HTTP 访问未变成强制跳转。

6. 回滚

bash
# 恢复 conf 备份
cp -a /data/nginx/conf/conf.d/ruoyi-office.conf.bak.https-XXXX \
      /data/nginx/conf/conf.d/ruoyi-office.conf
docker exec nginx nginx -t && docker exec nginx nginx -s reload

业务即可回到纯 HTTP。证书目录可保留不影响。

7. 常见问题

现象处理
challenge 404检查 ACME root 与 certbot -w 是否同为 .../html/acmenginx -t/reload
certbot DNS 失败getent hosts;补全 www A 记录
容器内证书 File not foundlive 软链出容器解析失败 → 用脚本拷贝实文件到 /data/nginx/ssl/
443 握手失败安全组、容器 -p 443:443、conf 是否 listen 443 ssl
HTTPS 页 OnlyOffice 白屏混合内容:http://…:18081 被拦 → 见 OnlyOffice 文档Nginx 配置说明locations-ruoyi-office.inc/onlyoffice 备选反代
天气运营台 Cookie双开阶段保持 ADMIN_COOKIE_SECURE=false;全站强制 HTTPS 后再改 true

8. 关联系统副作用

组件首期双开日后强制 HTTPS
现有 http:// 入口不变环境变量改为 https://
天气运营台ADMIN_COOKIE_SECURE=false改为 true
OnlyOffice :18081HTTP 页可用须 HTTPS 反代
前端硬编码 http仍可用逐步替换

9. 变更记录

日期操作备注
2026-07-30初版方案落地LE 签发 ruoyioffice.com(无 www);ssl 挂载 + 443 双开;cron 17 3 * * *;文档与续期脚本入库
联系我们

获取报价、演示和二开方案

微信咨询二维码

微信咨询

17156169080

添加时备注「RuoYi Office」

在线体验商业版