温馨提示×

centos怎么替换证书文件路径

小樊
47
2026-09-06 09:55:45
栏目: 智能运维

在 CentOS 上“替换证书文件路径”通常取决于你用的是哪种服务(Nginx、Apache、HAProxy、系统信任证书等)。下面按常见场景给你说明。


一、Web 服务(Nginx / Apache)替换证书路径

1️⃣ Nginx

  1. 编辑配置文件(常见位置):
vi /etc/nginx/nginx.conf
# 或
vi /etc/nginx/conf.d/*.conf
  1. 找到证书配置:
ssl_certificate     /old/path/fullchain.pem;
ssl_certificate_key /old/path/privkey.pem;
  1. 修改为新路径:
ssl_certificate     /new/path/fullchain.pem;
ssl_certificate_key /new/path/privkey.pem;
  1. 测试并重载:
nginx -t
systemctl reload nginx

2️⃣ Apache

  1. 编辑配置:
vi /etc/httpd/conf.d/ssl.conf
  1. 修改路径:
SSLCertificateFile /new/path/cert.pem
SSLCertificateKeyFile /new/path/privkey.pem
SSLCertificateChainFile /new/path/chain.pem
  1. 重启服务:
systemctl restart httpd

二、系统级证书信任路径(CA 证书)

如果你是要让系统信任新证书

CentOS 6/7

cp new-ca.crt /etc/pki/tls/certs/
update-ca-trust

CentOS 8 / Stream

cp new-ca.crt /etc/pki/ca-trust/source/anchors/
update-ca-trust

三、HAProxy 替换证书路径

vi /etc/haproxy/haproxy.cfg
bind *:443 ssl crt /new/path/cert.pem
systemctl reload haproxy

四、如果是 Let’s Encrypt(certbot)

不要直接改路径,用:

certbot renew --force-renewal

或重新签发:

certbot --nginx -d example.com

五、常见注意事项

  • 新证书文件权限建议:600
  • 属主:root:root
  • 修改后一定要 nginx -tapachectl configtest

如果你能告诉我: ✅ 用的是 Nginx / Apache / 其他 ✅ 是 网站证书 还是 系统 CA 证书

我可以直接给你精确命令

0