Skip to content

Commit d9316f5

Browse files
committed
refactor(nginx): 简化SSL配置并更新1Panel集成文档
移除手动SSL证书路径配置,改为使用1Panel自动管理 添加新的简化版nginx配置文件blog-site-simple.conf 更新部署脚本和文档以匹配新的配置流程 ``` 这个提交消息: 1. 使用refactor类型,因为这是对配置方式的重大重构 2. 指定scope为nginx,因为主要修改的是nginx配置 3. 简明描述了主要变更: - 简化SSL配置方式 - 添加新配置文件 - 更新相关文档和脚本 4. 保持在50字符以内 5. 使用中文并遵循所有格式要求
1 parent d996de3 commit d9316f5

5 files changed

Lines changed: 491 additions & 89 deletions

File tree

1PANEL-INTEGRATION.md

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -266,40 +266,40 @@ location ~* (wp-admin|wp-login|xmlrpc|\.php$) {
266266
- 访问 `https://your-server-ip:10086`
267267
- 使用管理员账户登录
268268

269-
2. **配置域名**
269+
2. **创建反向代理网站**
270270
- 进入 `网站``网站管理`
271-
- 添加新网站,设置域名
271+
- 点击 `创建网站`
272272
- 选择 `反向代理` 类型
273-
274-
3. **申请SSL证书**
275-
- 在网站详情页面点击 `SSL`
276-
- 选择 `Let's Encrypt` 或上传自己的证书
273+
- 设置域名(如:yourdomain.com)
274+
- 代理地址:`http://127.0.0.1:4321`
275+
276+
3. **添加自定义配置**
277+
- 在网站创建页面或编辑页面
278+
- 找到 `自定义配置` 选项
279+
- 复制 `1panel-configs/blog-site-simple.conf` 中的内容
280+
- 粘贴到自定义配置中
281+
282+
4. **申请SSL证书**
283+
- 网站创建成功后,进入网站详情页面
284+
- 点击 `SSL` 标签页
285+
- 选择 `Let's Encrypt` 免费证书或上传自己的证书
277286
- 点击申请并等待完成
287+
- 1Panel会自动处理SSL配置和HTTP重定向
278288

279-
4. **更新配置路径**
280-
281-
编辑 `1panel-configs/blog-site.conf`,更新SSL证书路径:
282-
```nginx
283-
ssl_certificate /opt/1panel/apps/openresty/openresty/conf/ssl/yourdomain.com/cert.pem;
284-
ssl_certificate_key /opt/1panel/apps/openresty/openresty/conf/ssl/yourdomain.com/key.pem;
285-
```
286-
287-
### 手动配置SSL
288-
289-
如果需要手动配置SSL证书:
289+
### 上传自有SSL证书
290290

291-
```bash
292-
# 创建SSL目录
293-
sudo mkdir -p /opt/1panel/apps/openresty/openresty/conf/ssl/yourdomain.com
291+
如果您有自己的SSL证书:
294292

295-
# 复制证书文件
296-
sudo cp your-cert.pem /opt/1panel/apps/openresty/openresty/conf/ssl/yourdomain.com/cert.pem
297-
sudo cp your-key.pem /opt/1panel/apps/openresty/openresty/conf/ssl/yourdomain.com/key.pem
293+
1. **在1Panel面板中上传**
294+
- 进入网站详情页面,点击 `SSL` 标签
295+
- 选择 `其他证书`
296+
- 上传证书文件(.crt 或 .pem)和私钥文件(.key)
297+
- 1Panel会自动验证并应用证书
298298

299-
# 设置权限
300-
sudo chown -R 1001:1001 /opt/1panel/apps/openresty/openresty/conf/ssl/
301-
sudo chmod 600 /opt/1panel/apps/openresty/openresty/conf/ssl/yourdomain.com/*
302-
```
299+
2. **证书自动续期**
300+
- Let's Encrypt证书会自动续期
301+
- 自有证书需要手动更新
302+
- 可以设置到期提醒
303303

304304
## 监控与维护
305305

@@ -320,14 +320,18 @@ sudo chmod 600 /opt/1panel/apps/openresty/openresty/conf/ssl/yourdomain.com/*
320320
#### 查看OpenResty日志
321321

322322
```bash
323-
# 访问日志
324-
sudo tail -f /opt/1panel/apps/openresty/openresty/logs/blog_access.log
323+
# 通过1Panel面板查看
324+
# 进入 网站 -> 网站管理 -> 选择网站 -> 日志
325325

326-
# 错误日志
327-
sudo tail -f /opt/1panel/apps/openresty/openresty/logs/blog_error.log
326+
# 或使用命令行查看
327+
sudo tail -f /www/wwwlogs/yourdomain.com.log
328+
sudo tail -f /www/wwwlogs/yourdomain.com.error.log
328329

329330
# 1Panel系统日志
330331
sudo journalctl -u 1panel -f
332+
333+
# Docker容器日志
334+
docker logs 1panel-openresty
331335
```
332336

333337
### 性能监控
@@ -433,21 +437,25 @@ docker restart 1panel-openresty
433437

434438
**排查步骤**:
435439
```bash
436-
# 检查证书文件
437-
sudo ls -la /opt/1panel/apps/openresty/openresty/conf/ssl/yourdomain.com/
438-
439-
# 检查证书有效期
440-
openssl x509 -in /path/to/cert.pem -text -noout | grep -A 2 "Validity"
440+
# 在1Panel面板中检查
441+
# 进入 网站 -> 网站管理 -> SSL 查看证书状态
441442

442443
# 测试SSL配置
443444
openssl s_client -connect yourdomain.com:443 -servername yourdomain.com
445+
446+
# 检查域名解析
447+
nslookup yourdomain.com
448+
dig yourdomain.com
449+
450+
# 检查端口访问
451+
telnet yourdomain.com 443
444452
```
445453

446454
**解决方案**:
447-
- 通过1Panel重新申请证书
448-
- 检查域名解析是否正确
449-
-
450-
确认证书文件路径和权限
455+
- 在1Panel面板中重新申请Let's Encrypt证书
456+
- 检查域名解析是否指向正确IP
457+
- 确认防火墙开放443端口
458+
- 验证域名所有权
451459

452460
#### 4. 数据库连接失败
453461

1panel-configs/SETUP-GUIDE.md

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
# 1Panel OpenResty 配置步骤指南
2+
3+
## 📋 配置前准备
4+
5+
在开始配置之前,请确保:
6+
7+
✅ 1Panel面板已安装并运行
8+
✅ OpenResty应用已通过1Panel应用商店安装
9+
✅ 博客Docker服务已启动(端口4321和8080可访问)
10+
✅ 域名已解析到服务器IP
11+
12+
## 🚀 第一步:启动博客服务
13+
14+
```bash
15+
# 进入项目目录
16+
cd /path/to/Blog
17+
18+
# 初始化环境
19+
./deploy-1panel.sh setup
20+
21+
# 构建并启动服务
22+
./deploy-1panel.sh build
23+
./deploy-1panel.sh start
24+
25+
# 验证服务运行
26+
./deploy-1panel.sh health
27+
```
28+
29+
## 🌐 第二步:在1Panel中创建网站
30+
31+
### 2.1 登录1Panel面板
32+
33+
1. 浏览器访问:`https://your-server-ip:10086`
34+
2. 使用管理员账户登录
35+
36+
### 2.2 创建反向代理网站
37+
38+
1. 进入 **网站****网站管理**
39+
2. 点击 **创建网站** 按钮
40+
3. 填写网站信息:
41+
- **类型**:选择 `反向代理`
42+
- **主域名**:填写您的域名(如:`example.com`
43+
- **代理地址**:填写 `http://127.0.0.1:4321`
44+
- **备注**`博客系统前端`
45+
46+
### 2.3 添加自定义配置
47+
48+
在创建页面或网站编辑页面中:
49+
50+
1. 找到 **自定义配置****高级配置** 选项
51+
2. 复制下面的配置内容并粘贴:
52+
53+
```nginx
54+
# 请求体大小限制
55+
client_max_body_size 10M;
56+
57+
# 速率限制定义
58+
limit_req_zone $binary_remote_addr zone=blog_api:10m rate=10r/s;
59+
limit_req_zone $binary_remote_addr zone=blog_login:10m rate=1r/s;
60+
61+
# API路由配置
62+
location /api/ {
63+
limit_req zone=blog_api burst=20 nodelay;
64+
65+
proxy_pass http://127.0.0.1:8080;
66+
proxy_http_version 1.1;
67+
proxy_set_header Upgrade $http_upgrade;
68+
proxy_set_header Connection 'upgrade';
69+
proxy_set_header Host $host;
70+
proxy_set_header X-Real-IP $remote_addr;
71+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
72+
proxy_set_header X-Forwarded-Proto $scheme;
73+
proxy_cache_bypass $http_upgrade;
74+
75+
# 超时设置
76+
proxy_connect_timeout 30s;
77+
proxy_send_timeout 30s;
78+
proxy_read_timeout 30s;
79+
80+
# 错误处理
81+
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
82+
}
83+
84+
# 登录接口限流
85+
location /api/auth/login {
86+
limit_req zone=blog_login burst=5 nodelay;
87+
88+
proxy_pass http://127.0.0.1:8080;
89+
proxy_http_version 1.1;
90+
proxy_set_header Host $host;
91+
proxy_set_header X-Real-IP $remote_addr;
92+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
93+
proxy_set_header X-Forwarded-Proto $scheme;
94+
}
95+
96+
# 静态资源缓存
97+
location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff|woff2|ttf|svg)$ {
98+
proxy_pass http://127.0.0.1:4321;
99+
expires 1y;
100+
add_header Cache-Control "public, immutable";
101+
add_header X-Cache-Status "STATIC";
102+
}
103+
104+
# 健康检查端点
105+
location /health {
106+
access_log off;
107+
return 200 "healthy\n";
108+
add_header Content-Type text/plain;
109+
}
110+
111+
# 安全防护
112+
location ~ /\. {
113+
deny all;
114+
access_log off;
115+
log_not_found off;
116+
}
117+
118+
location ~* (wp-admin|wp-login|xmlrpc|admin|phpmyadmin|\.php$) {
119+
deny all;
120+
access_log off;
121+
log_not_found off;
122+
return 444;
123+
}
124+
125+
location ~* \.(env|git|svn|htaccess|htpasswd)$ {
126+
deny all;
127+
access_log off;
128+
log_not_found off;
129+
return 444;
130+
}
131+
```
132+
133+
3. 点击 **创建** 完成网站创建
134+
135+
## 🔒 第三步:配置SSL证书
136+
137+
### 3.1 使用Let's Encrypt免费证书(推荐)
138+
139+
1. 网站创建成功后,进入网站详情页面
140+
2. 点击 **SSL** 标签页
141+
3. 选择 **Let's Encrypt**
142+
4. 填写邮箱地址
143+
5. 点击 **申请** 并等待完成
144+
6. 1Panel会自动配置HTTPS重定向
145+
146+
### 3.2 上传自有SSL证书
147+
148+
1. 在SSL页面选择 **其他证书**
149+
2. 上传证书文件(.crt 或 .pem)
150+
3. 上传私钥文件(.key)
151+
4. 点击 **保存**
152+
153+
## ✅ 第四步:验证配置
154+
155+
### 4.1 测试网站访问
156+
157+
```bash
158+
# 测试HTTP(应该重定向到HTTPS)
159+
curl -I http://yourdomain.com
160+
161+
# 测试HTTPS
162+
curl -I https://yourdomain.com
163+
164+
# 测试API接口
165+
curl https://yourdomain.com/api/health
166+
```
167+
168+
### 4.2 检查服务状态
169+
170+
```bash
171+
# 检查博客服务
172+
./deploy-1panel.sh status
173+
174+
# 查看日志
175+
./deploy-1panel.sh logs
176+
```
177+
178+
### 4.3 1Panel面板检查
179+
180+
1.**网站管理** 中查看网站状态
181+
2. 检查SSL证书有效期
182+
3. 查看访问日志和错误日志
183+
184+
## 🛠️ 常见问题解决
185+
186+
### 问题1:502 Bad Gateway
187+
188+
**原因**:后端服务未启动或端口不通
189+
190+
**解决**
191+
```bash
192+
# 检查服务状态
193+
docker ps
194+
./deploy-1panel.sh health
195+
196+
# 重启服务
197+
./deploy-1panel.sh restart
198+
```
199+
200+
### 问题2:SSL证书申请失败
201+
202+
**原因**:域名解析未生效或端口80被占用
203+
204+
**解决**
205+
1. 检查域名解析:`nslookup yourdomain.com`
206+
2. 确保端口80可访问
207+
3. 临时停止其他Web服务
208+
209+
### 问题3:API接口无法访问
210+
211+
**原因**:后端服务未启动或配置错误
212+
213+
**解决**
214+
```bash
215+
# 检查后端服务
216+
curl http://127.0.0.1:8080/health
217+
218+
# 查看后端日志
219+
./deploy-1panel.sh logs backend
220+
```
221+
222+
## 📝 配置完成检查清单
223+
224+
- [ ] 博客Docker服务正常运行
225+
- [ ] 1Panel网站创建成功
226+
- [ ] 自定义配置已添加
227+
- [ ] SSL证书申请并配置成功
228+
- [ ] HTTP自动重定向到HTTPS
229+
- [ ] 前端页面可正常访问
230+
- [ ] API接口可正常访问
231+
- [ ] 静态资源缓存正常
232+
- [ ] 安全防护规则生效
233+
234+
## 🔄 后续维护
235+
236+
### 定期备份
237+
238+
```bash
239+
# 数据库备份
240+
./deploy-1panel.sh backup
241+
242+
# 配置备份
243+
cp .env .env.backup
244+
```
245+
246+
### 更新应用
247+
248+
```bash
249+
# 更新博客应用
250+
./deploy-1panel.sh update
251+
```
252+
253+
### 监控检查
254+
255+
1. 定期查看1Panel监控面板
256+
2. 检查SSL证书到期时间
257+
3. 查看访问日志和错误日志
258+
4. 监控服务器资源使用情况
259+
260+
---
261+
262+
🎉 恭喜!您的博客系统已成功部署并配置完成!
263+
264+
如有问题,请参考 [1PANEL-INTEGRATION.md](1PANEL-INTEGRATION.md) 获取更详细的说明。

0 commit comments

Comments
 (0)