114 lines
2.1 KiB
Markdown
114 lines
2.1 KiB
Markdown
# SSL证书配置说明
|
||
|
||
## 当前状态
|
||
|
||
**域名**: QD.YYDD.AI
|
||
**服务器IP**: 45.192.99.48
|
||
**域名当前解析**: 198.18.0.113
|
||
|
||
⚠️ **重要**: 域名解析尚未指向服务器IP,需要先配置DNS解析。
|
||
|
||
---
|
||
|
||
## 步骤1: 配置DNS解析
|
||
|
||
在域名管理面板中,将 `QD.YYDD.AI` 的A记录指向 `45.192.99.48`
|
||
|
||
---
|
||
|
||
## 步骤2: 验证域名解析
|
||
|
||
```bash
|
||
# 在本地执行
|
||
nslookup QD.YYDD.AI
|
||
# 应该返回: 45.192.99.48
|
||
```
|
||
|
||
---
|
||
|
||
## 步骤3: 申请Let's Encrypt证书
|
||
|
||
**方法1: 使用certbot standalone模式(推荐)**
|
||
|
||
```bash
|
||
ssh root@45.192.99.48
|
||
systemctl stop nginx
|
||
certbot certonly --standalone -d QD.YYDD.AI --non-interactive --agree-tos --email admin@yydd.ai
|
||
systemctl start nginx
|
||
```
|
||
|
||
**方法2: 使用certbot nginx模式**
|
||
|
||
```bash
|
||
ssh root@45.192.99.48
|
||
certbot --nginx -d QD.YYDD.AI --non-interactive --agree-tos --email admin@yydd.ai
|
||
```
|
||
|
||
---
|
||
|
||
## 步骤4: 配置Nginx使用SSL证书
|
||
|
||
证书申请成功后,证书文件将位于:
|
||
- `/etc/letsencrypt/live/QD.YYDD.AI/fullchain.pem`
|
||
- `/etc/letsencrypt/live/QD.YYDD.AI/privkey.pem`
|
||
|
||
然后更新Nginx配置(已包含在配置文件中)。
|
||
|
||
---
|
||
|
||
## 步骤5: 重启Nginx
|
||
|
||
```bash
|
||
nginx -t
|
||
systemctl restart nginx
|
||
```
|
||
|
||
---
|
||
|
||
## 当前配置说明
|
||
|
||
已配置:
|
||
- ✅ HTTPS (443端口)
|
||
- ✅ HTTP重定向到HTTPS (80端口)
|
||
- ✅ 关闭所有缓存
|
||
- ✅ 上传限制100M
|
||
- ✅ 使用域名QD.YYDD.AI
|
||
|
||
待完成:
|
||
- ⏳ SSL证书申请(需等待DNS解析生效)
|
||
- ⏳ 自动续期配置
|
||
|
||
---
|
||
|
||
## 自动续期
|
||
|
||
Let's Encrypt证书有效期90天,需要配置自动续期:
|
||
|
||
```bash
|
||
# 测试续期
|
||
certbot renew --dry-run
|
||
|
||
# 设置自动续期(cron任务已自动配置)
|
||
systemctl status certbot.timer
|
||
```
|
||
|
||
---
|
||
|
||
## 临时使用自签名证书
|
||
|
||
如果需要立即测试,可以使用自签名证书(浏览器会显示警告):
|
||
|
||
```bash
|
||
mkdir -p /etc/nginx/ssl
|
||
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
|
||
-keyout /etc/nginx/ssl/QD.YYDD.AI.key \
|
||
-out /etc/nginx/ssl/QD.YYDD.AI.crt \
|
||
-subj '/CN=QD.YYDD.AI'
|
||
```
|
||
|
||
然后在Nginx配置中使用:
|
||
```nginx
|
||
ssl_certificate /etc/nginx/ssl/QD.YYDD.AI.crt;
|
||
ssl_certificate_key /etc/nginx/ssl/QD.YYDD.AI.key;
|
||
```
|