温馨提示×

centos替换证书怎么做

小樊
33
2026-10-20 19:26:56
栏目: 智能运维

在 CentOS 上“替换证书”通常指的是替换 Web 服务(如 Nginx / Apache)、系统级证书 或 服务通信证书(如 HTTPS、LDAP、邮件等)。下面按常见场景给你说明。


一、Nginx 替换 SSL 证书(最常见)

1. 准备新证书文件

一般包含:

  • xxx.crt(证书)
  • xxx.key(私钥)
  • (可选)chain.crt / fullchain.crt

2. 上传并覆盖证书

cp your_domain.crt /etc/nginx/ssl/your_domain.crt
cp your_domain.key /etc/nginx/ssl/your_domain.key

3. 修改 Nginx 配置(如未改路径可跳过)

ssl_certificate     /etc/nginx/ssl/your_domain.crt;
ssl_certificate_key /etc/nginx/ssl/your_domain.key;

4. 检查配置并重启

nginx -t
systemctl restart nginx

二、Apache 替换 SSL 证书

1. 替换证书

cp your_domain.crt /etc/pki/tls/certs/your_domain.crt
cp your_domain.key /etc/pki/tls/private/your_domain.key

2. 修改配置(示例)

SSLCertificateFile /etc/pki/tls/certs/your_domain.crt
SSLCertificateKeyFile /etc/pki/tls/private/your_domain.key

3. 重启 Apache

httpd -t
systemctl restart httpd

三、替换系统信任的 CA 证书(CentOS 7)

1. 复制 CA 证书

cp your_ca.crt /etc/pki/ca-trust/source/anchors/

2. 更新信任库

update-ca-trust extract

四、使用 certbot(Let’s Encrypt)自动替换

如果原来是 certbot 签发的:

certbot renew
# 或强制
certbot renew --force-renewal

Nginx/Apache 会自动 reload。


五、常见注意事项

  • 私钥权限:
    chmod 600 your_domain.key
    chown root:root your_domain.key
    
  • 替换后一定要 重启服务
  • 检查端口监听:
    ss -lntp | grep 443
    

六、如果你是指“其他证书”

你也可以告诉我具体是哪一种:

  • ✅ Nginx / Apache HTTPS
  • ✅ CentOS 系统 CA
  • ✅ Kubernetes / Docker
  • ✅ LDAP / SMTP / MySQL SSL
  • ✅ 自签名证书

我可以给你更精确的命令。

0 踩