docs: Add HTTPS configuration guide for 3D.YYDD.AI

- Three solutions: Nginx+Certbot, Cloudflare SSL, acme.sh
- Detailed step-by-step instructions
- FRP configuration for HTTPS
- Troubleshooting guide
- Comparison of different approaches
This commit is contained in:
chenpei 2025-10-26 17:31:57 +08:00
parent 3bac4f0e11
commit 3417b5b061

429
HTTPS_SETUP.md Normal file
View File

@ -0,0 +1,429 @@
# HTTPS 配置指南 - 3D.YYDD.AI
## 概述
为域名 `3D.YYDD.AI` 配置免费的 HTTPS 证书(Let's Encrypt)
**服务器信息:**
- 公网IP:180.97.221.140
- 域名:3D.YYDD.AI
- 当前端口:2320 (HTTP)
- 目标:配置 443 端口 (HTTPS)
- 架构:云服务器 → FRP穿透 → NAS服务器
## 方案选择
### 方案一:Nginx + Certbot(推荐)
适用于云服务器上直接配置反向代理
### 方案二:Cloudflare SSL(最简单)
适用于使用 Cloudflare 作为 DNS 解析
## 方案一:Nginx + Let's Encrypt(免费证书)
### 1. 在云服务器上安装 Nginx 和 Certbot
```bash
# SSH 登录到云服务器 180.97.221.140
ssh root@180.97.221.140
# CentOS/RHEL
sudo yum install -y nginx certbot python3-certbot-nginx
# Ubuntu/Debian
sudo apt update
sudo apt install -y nginx certbot python3-certbot-nginx
```
### 2. 配置 Nginx 反向代理
创建配置文件:`/etc/nginx/conf.d/3d-yydd-ai.conf`
```nginx
# HTTP 配置(用于 Let's Encrypt 验证和重定向)
server {
listen 80;
server_name 3d.yydd.ai www.3d.yydd.ai;
# Let's Encrypt 验证目录
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
# 其他请求重定向到 HTTPS
location / {
return 301 https://$server_name$request_uri;
}
}
# HTTPS 配置
server {
listen 443 ssl http2;
server_name 3d.yydd.ai www.3d.yydd.ai;
# SSL 证书路径(稍后由 certbot 自动填充)
ssl_certificate /etc/letsencrypt/live/3d.yydd.ai/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/3d.yydd.ai/privkey.pem;
# SSL 优化配置
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
# 安全头部
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
# 反向代理到 NAS 服务器(通过 FRP 穿透)
location / {
# 代理到 FRP 映射的本地端口
proxy_pass http://127.0.0.1:2320;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
# 大文件上传支持
client_max_body_size 10240M;
proxy_request_buffering off;
# 超时设置
proxy_connect_timeout 3600s;
proxy_send_timeout 3600s;
proxy_read_timeout 3600s;
}
}
```
### 3. 创建证书验证目录
```bash
sudo mkdir -p /var/www/certbot
sudo chown -R nginx:nginx /var/www/certbot
```
### 4. 测试 Nginx 配置
```bash
sudo nginx -t
```
### 5. 启动 Nginx
```bash
sudo systemctl start nginx
sudo systemctl enable nginx
```
### 6. 获取 Let's Encrypt 证书
```bash
# 确保域名已经解析到 180.97.221.140
# 可以用 ping 或 nslookup 验证
ping 3d.yydd.ai
# 获取证书
sudo certbot --nginx -d 3d.yydd.ai -d www.3d.yydd.ai
# 按照提示操作:
# 1. 输入邮箱(用于证书过期提醒)
# 2. 同意服务条款
# 3. 选择是否重定向 HTTP 到 HTTPS(选择 2 - 强制 HTTPS)
```
### 7. 验证证书
```bash
# 查看证书信息
sudo certbot certificates
# 测试自动续期
sudo certbot renew --dry-run
```
### 8. 设置自动续期
Let's Encrypt 证书有效期为 90 天,需要定期续期:
```bash
# Certbot 会自动创建 cron 任务
# 查看续期任务
sudo systemctl status certbot-renew.timer
# 手动续期(测试)
sudo certbot renew
```
## 方案二:Cloudflare SSL(零配置)
如果域名使用 Cloudflare 作为 DNS:
### 1. 登录 Cloudflare
访问:https://dash.cloudflare.com
### 2. 添加域名(如果还没有)
- 添加站点:YYDD.AI
- 按照提示修改域名服务器
### 3. 配置 DNS 记录
```
类型 名称 内容 代理状态
A 3d 180.97.221.140 已代理(橙色云朵)
```
### 4. 配置 SSL/TLS
在 Cloudflare 面板:
1. **SSL/TLS** → **概述**
- 选择:**灵活(Flexible)** 或 **完全(Full)**
- 灵活:Cloudflare到用户HTTPS,Cloudflare到服务器HTTP
- 完全:两端都使用HTTPS(推荐,但需要服务器有证书)
2. **SSL/TLS** → **边缘证书**
- 启用:始终使用 HTTPS
- 自动 HTTPS 重写:开启
- 最低 TLS 版本:TLS 1.2
### 5. 修改 Nginx 配置(使用 Cloudflare)
```nginx
server {
listen 80;
server_name 3d.yydd.ai;
location / {
proxy_pass http://127.0.0.1:2320;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 10240M;
proxy_request_buffering off;
}
}
```
优势:
- ✓ 零配置,Cloudflare 自动提供 SSL
- ✓ 免费 CDN 加速
- ✓ DDoS 防护
- ✓ 自动续期
## 方案三:acme.sh(轻量级)
### 1. 安装 acme.sh
```bash
curl https://get.acme.sh | sh
source ~/.bashrc
```
### 2. 获取证书(DNS验证)
```bash
# 使用 DNS API(推荐)
export CF_Token="你的Cloudflare_API_Token"
export CF_Account_ID="你的Cloudflare_Account_ID"
acme.sh --issue --dns dns_cf -d 3d.yydd.ai -d www.3d.yydd.ai
```
### 3. 安装证书到 Nginx
```bash
acme.sh --install-cert -d 3d.yydd.ai \
--key-file /etc/nginx/ssl/3d.yydd.ai.key \
--fullchain-file /etc/nginx/ssl/3d.yydd.ai.crt \
--reloadcmd "systemctl reload nginx"
```
## FRP 配置调整
如果需要在 NAS 服务器上配置 HTTPS,需要修改 FRP 配置:
### 在云服务器(frps.toml)
```toml
bindPort = 7000
vhostHTTPPort = 2320 # HTTP
vhostHTTPSPort = 2443 # HTTPS(新增)
```
### 在 NAS 服务器(frpc.toml)
```toml
serverAddr = "180.97.221.140"
serverPort = 7000
[[proxies]]
name = "youyidian-3d-http"
type = "http"
localIP = "127.0.0.1"
localPort = 4320
customDomains = ["3d.yydd.ai"]
[[proxies]]
name = "youyidian-3d-https"
type = "https"
localIP = "127.0.0.1"
localPort = 4320
customDomains = ["3d.yydd.ai"]
```
## 验证 HTTPS
### 1. 浏览器访问
```
https://3d.yydd.ai
```
### 2. 命令行测试
```bash
# 测试 SSL 证书
curl -I https://3d.yydd.ai
# 详细 SSL 信息
openssl s_client -connect 3d.yydd.ai:443 -servername 3d.yydd.ai
```
### 3. 在线工具
- SSL Labs测试:https://www.ssllabs.com/ssltest/
- 输入:3d.yydd.ai
- 目标评分:A 或 A+
## 常见问题
### 1. 证书获取失败
```bash
# 检查域名解析
nslookup 3d.yydd.ai
dig 3d.yydd.ai
# 检查80端口是否开放
sudo firewall-cmd --list-all
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-service=https --permanent
sudo firewall-cmd --reload
```
### 2. Nginx 启动失败
```bash
# 查看错误日志
sudo journalctl -u nginx -f
# 检查配置语法
sudo nginx -t
# 查看端口占用
sudo netstat -tlnp | grep :80
sudo netstat -tlnp | grep :443
```
### 3. 证书过期
```bash
# 手动续期
sudo certbot renew --force-renewal
# 查看证书有效期
sudo certbot certificates
```
### 4. 混合内容警告
如果页面有 HTTP 资源:
```nginx
# 在 Nginx 配置中添加
add_header Content-Security-Policy "upgrade-insecure-requests";
```
## 推荐方案对比
| 方案 | 难度 | 成本 | 性能 | 维护 |
|-----|------|------|------|------|
| Nginx + Certbot | ⭐⭐⭐ | 免费 | 高 | 自动续期 |
| Cloudflare | ⭐ | 免费 | 高(CDN) | 零维护 |
| acme.sh | ⭐⭐ | 免费 | 高 | 自动续期 |
## 建议
**如果域名已在 Cloudflare:**
→ 使用 **方案二(Cloudflare SSL)**
- 最简单,零配置
- 免费 CDN 加速
- 自动 HTTPS
**如果需要完全控制:**
→ 使用 **方案一(Nginx + Certbot)**
- 完全掌控
- 性能最佳
- 适合企业环境
## 部署步骤总结
### 快速部署(Cloudflare)
```bash
1. Cloudflare 添加 DNS 记录
A 3d 180.97.221.140 代理(橙色)
2. 启用 SSL/TLS(灵活模式)
3. 完成!访问 https://3d.yydd.ai
```
### 完整部署(Nginx + Let's Encrypt)
```bash
1. 安装 Nginx 和 Certbot
sudo yum install -y nginx certbot python3-certbot-nginx
2. 配置 Nginx
sudo vi /etc/nginx/conf.d/3d-yydd-ai.conf
3. 启动 Nginx
sudo systemctl start nginx
4. 获取证书
sudo certbot --nginx -d 3d.yydd.ai
5. 完成!访问 https://3d.yydd.ai
```
## 下一步
1. ✅ 修复 TypeScript 编译错误
2. ✅ 重新部署到 Docker
3. ⏳ 配置域名 DNS 解析
4. ⏳ 选择并实施 HTTPS 方案
5. ⏳ 测试 HTTPS 访问
---
**配置时间:** 2025-10-26
**域名:** 3D.YYDD.AI
**服务器:** 180.97.221.140
**状态:** 待配置