企业SSL 证书管理指南

文章从以下几个部分展开

  • SSL证书的用途和使用场景
  • SSL证书的申请类型和实现方式
  • SSL证书的管理
  • SSL证书的续签

一、SSL 证书的用途和使用场景

1.1 为什么要使用 SSL 证书?

复制代码
1.	数据安全 🛡️
   - 在 HTTP 传输中,TCP 包可以被截获,攻击者可以直接获取数据内容(比如用户名、密码、API Key)。
   - HTTPS 通过 SSL/TLS 加密通信,即使数据被拦截也无法解密,有效防止中间人攻击(MITM)。

2.	用户体验与信任 👀
   - 现代浏览器会对HTTP 站点标红,用户会看到"不安全"的提示,影响信任感。
   - HTTPS 站点 会在地址栏显示 小绿锁 🔒,提升安全感和专业度。

3.	合规性与政策要求 📜
   - 某些服务强制要求 HTTPS(如:Google 强制要求 HTTPS,HTTP 网站会影响 SEO 排名)。
   - PCI DSS(支付卡行业数据安全标准)等要求敏感数据必须加密传输。

1.2 SSL 证书的主要使用场景

复制代码
1.	对外提供 Web / WebSocket 服务 🌐
    常见场景:
   - Web 服务器(Nginx、Apache、Tomcat)
   - WebSocket 服务器(用于即时通讯、在线协作)

2.	API 保护 & 认证 🔑
   - API Server(Restful API / GraphQL / gRPC)
   - 需要确保API Key、JWT Token 传输安全,防止泄露

3.	企业内部服务 & 远程办公 🏢
   - 内部管理系统(如 Jenkins、GitLab、Kubernetes Dashboard)
   - VPN / 远程桌面 也需要证书加密,防止流量被窃取

1.3 证书申请方式及适用场景

方式 适用场景 优点 缺点
AWS ACM 证书 AWS 负载均衡、CloudFron 自动续期、免费 仅限 AWS 内部使用
Cloudflare SSL 域名托管在 Cloudflare 免费、隐藏源站 不能直接访问源站
购买商业 SSL 企业、银行、电商 可信度高 费用高,需要手动续期
自签名 SSL 内部测试、私有 API 免费、灵活 浏览器不信任,不适合公网
Cloudflare Tunnel 服务器无公网 IP 免证书、隐藏源站 依赖 Cloudflare,只适用于小型企业
公网免费证书 公司内部访问、个人网站 有自己的域名即可 3个月到期需要考虑续期,可以通过api自动续期

二、证书的管理

上一篇的1.3中已经列出了证书的申请方式,我接下来演示公网免费证书的申请

切记每一种方式都有适用场景,用什么完全取决于业务需求

由于是在route53下创建需要用到aws凭据和IAM用户 key

2.1、IAM权限

yaml 复制代码
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Route53DNSValidation",
            "Effect": "Allow",
            "Action": [
                "route53:GetChange",
                "route53:ChangeResourceRecordSets",
                "route53:ListResourceRecordSets"
            ],
            "Resource": [
                "arn:aws:route53:::hostedzone/*",
                "arn:aws:route53:::change/*"
            ]
        },
        {
            "Sid": "Route53ListHostedZones",
            "Effect": "Allow",
            "Action": [
                "route53:ListHostedZones",
                "route53:ListHostedZonesByName"
            ],
            "Resource": "*"
        }
    ]
}

2.2、配置aws凭据

创建用户后生成API Key

shell 复制代码
mkdir ~/.aws
echo "[default]
aws_access_key_id = YOUR_ACCESS_KEY
aws_secret_access_key = YOUR_SECRET_KEY" > ~/.aws/credentials
chmod 600 ~/.aws/credentials

2.3、安装certbot

这里安装的route53插件,通过我们上面的凭据去调用route53 API

shell 复制代码
apt update
apt install certbot python3-certbot-dns-route53

2.4、执行证书申请操作

通过route53 API完成DNS验证

shell 复制代码
DOMAIN="domain.com"
EMAIL="jarvan@domain.com"

certbot certonly \
  --dns-route53 \
  --dns-route53-propagation-seconds 30 \
  -d "$DOMAIN" \
  -d "*.$DOMAIN" \
  --email "$EMAIL" \
  --agree-tos \
  --non-interactive \
  --server https://acme-v02.api.letsencrypt.org/directory

创建后我我并未发现有验证的那条dns记录,最终总结出了Let's Encrypt 验证dns的流程

  • Certbot 创建一个 _acme-challenge.csconsulting.live 的 TXT 记录
  • Let's Encrypt 服务器验证这个记录
  • 验证成功后,Certbot 自动删除这个 TXT 记录
  • 最后颁发证书

创建完成后会提示证书的路径和证书到期时间,并且还会说明证书会自动续期,因为我们是通过api方式请求的

提示信息如下

shell 复制代码
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Requesting a certificate for csconsulting.live and *.csconsulting.live
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/csconsulting.live/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/csconsulting.live/privkey.pem
This certificate expires on 2025-05-13.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le

2.5、证书的续订

证书在到期一个月时可以进行续订

续订后需要重nginx,因为

  • 证书更新后,Certbot 会在 /etc/letsencrypt/live/你的域名/ 下生成新的证书文件
  • Nginx 不会自动检测到证书文件的更新
  • Nginx 在启动时会将证书加载到内存中,如果不重启/重载,它会继续使用旧的证书

即使是购买的公网证书也需要重新上传证书后重启服务

查看证书状态

shell 复制代码
$ certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
  Certificate Name: csconsulting.live
    Serial Number: 3244e0c60c7f5cb1507b417a7d18c281e29
    Key Type: RSA
    Domains: csconsulting.live *.csconsulting.live
    Expiry Date: 2025-05-15 02:11:36+00:00 (VALID: 89 days)
    Certificate Path: /etc/letsencrypt/live/csconsulting.live/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/csconsulting.live/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

测试续期

shell 复制代码
$ certbot renew --dry-run 
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/csconsulting.live.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Simulating renewal of an existing certificate for csconsulting.live and *.csconsulting.live

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all simulated renewals succeeded: 
  /etc/letsencrypt/live/csconsulting.live/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

cerbot.timer是定时器单元,下面还有定时器服务

shell 复制代码
$ systemctl status certbot.timer
● certbot.timer - Run certbot twice daily
     Loaded: loaded (/lib/systemd/system/certbot.timer; enabled; vendor preset: enabled)
     Active: active (waiting) since Wed 2025-02-12 10:32:06 CST; 2 days ago
    Trigger: Fri 2025-02-14 16:33:53 CST; 5h 3min left
   Triggers: ● certbot.service

Feb 12 10:32:06 ip-10-240-20-253 systemd[1]: Started Run certbot twice daily.

查看定时器状

shell 复制代码
$ systemctl cat certbot.timer
# /lib/systemd/system/certbot.timer
[Unit]
Description=Run certbot twice daily

[Timer]
OnCalendar=*-*-* 00,12:00:00
RandomizedDelaySec=43200
Persistent=true

[Install]
WantedBy=timers.target


$ systemctl cat certbot.service
# /lib/systemd/system/certbot.service
[Unit]
Description=Certbot
Documentation=file:///usr/share/doc/python-certbot-doc/html/index.html
Documentation=https://certbot.eff.org/docs
[Service]
Type=oneshot
ExecStart=/usr/bin/certbot -q renew
PrivateTmp=true

解释配置

shell 复制代码
[Timer]
OnCalendar=*-*-* 00,12:00:00     # 每天在 00:00 和 12:00 运行
RandomizedDelaySec=43200         # 随机延迟最多12小时(43200秒)
Persistent=true                  # 如果错过运行时间(比如系统关机),下次启动会补充运行
shell 复制代码
[Service]
Type=oneshot                     # 运行一次就结束的服务
ExecStart=/usr/bin/certbot -q renew  # 实际执行的命令,-q表示安静模式
PrivateTmp=true                 # 使用私有临时目录,增加安全性
相关推荐
MC皮蛋侠客9 小时前
DNP3 系列(十二):测试与工具链——模拟器、Wireshark 与一致性测试
网络·wireshark·dnp3
虎王物联10 小时前
工业Modbus TCP协议深度实战:STM32 HAL库实现从机通信与数据上云
stm32·物联网·网络协议·tcp/ip·嵌入式
观测云11 小时前
Fastjson 高危 RCE(CVE-2026-16723):如何用观测云快速发现并完成修复
网络·安全·可观测性·观测云
楷哥爱开发13 小时前
TikTok Shop新加坡本土店入驻:如何选择新加坡本土住宅IP?
网络·网络协议·tcp/ip
网安蟹佬霸13 小时前
# 网络流量分析实战:从Wireshark到入侵检测系统构建(2026最新版,附完整流量分析链与IDS规则集)
网络·测试工具·安全·开源·wireshark·密码学·哈希算法
昌原的儿子LEO16 小时前
进程和线程(2)
linux·服务器·网络
Zzzzmo_16 小时前
【网络原理】TCP/IP协议02
网络·tcp/ip
DianSan_ERP16 小时前
WMS接入电商平台自动化履约实战:一张订单从平台到出库的接口时序设计
java·前端·网络·数据库·安全·架构·自动化
数据知道16 小时前
漏洞挖掘方法论:从 Fuzz 到 0day 的思维框架
网络·安全·web安全·网络安全
智购科技自动售货机工厂16 小时前
2026自动售货机语音支付模块集成:从声纹识别到支付闭环的工程实践~YH
大数据·服务器·网络·数据库·人工智能