Files
blog/content/posts/the-method-of-replacing-the-SSL-certificate/index.md
changsongd a7012934e0
All checks were successful
Gitea Actions Demo / build-and-deploy-to-local-server (push) Successful in 3m47s
Gitea Actions Demo / deploy-to-remote-server (push) Successful in 3s
posts: 更换SSL证书的方法
2025-06-12 21:37:12 +08:00

76 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
date: '2025-06-12T20:32:04+08:00'
draft: false
title: '更换SSL证书的方法'
---
## 背景说明
- 网站通过NGINX代理
- NGINX通过Docker部署
- 域名通过阿里云购入
- SSL证书通过阿里云申请
## 更换方法
基于上面的背景更换SSL证书共分为四步
1. 申请新的SSL证书
![alt text](image.png)
点击```创建证书```,在弹出的页面中,输入```域名名称```,然后点击```提交审核```。等待大概10分钟就会通过审核并完成证书签发这个过程无需做任何操作因为域名和SSL证书都是通过阿里云所以会自动添加记录值和验证。
2. 下载证书
![alt text](image-1.png)
服务器类型为Nginx点击下载。解压之后可以得到```.key```和```.pem```文件。
3. 配置新的SSL证书
把```.key```和```.pem```文件放在```cert/```目录下(替换原来的证书文件)。
4. 重启NGINX服务
```bash
docker restart nginx
```
至此SSL证书更换完成。
## 后记
如果是首次配置SSL证书还需要在nginx的配置文件中添加如下内容
```nginx
server
{
listen 443 ssl;
server_name [your domain name];
ssl_certificate cert/1970666.xyz.pem;
ssl_certificate_key cert/1970666.xyz.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
location / {
root /usr/share/nginx/html/blog;
index index.html;
try_files $uri $uri/ =404;
}
access_log /logs/blog.log;
}
server {
listen 80;
server_name [your domain name];
rewrite ^(.*)$ https://$host$1;
location / {
index index.html index.htm;
}
}
```