1Panel上的免费WAF长亭雷池搭配openresty的用法
字数 1144 2025-08-10 16:34:39
1Panel上部署长亭雷池WAF与OpenResty集成指南
1. 概述
本教程详细讲解如何在1Panel面板上部署长亭雷池WAF(社区版)并与OpenResty集成,实现Web应用防火墙功能。主要内容包括:
- OpenResty网络配置调整
- 站点监听端口修改
- 雷池WAF的安装与配置
- SSL证书自动更新方案
2. 准备工作
- 已安装1Panel面板(默认路径为/opt/1panel)
- 已部署OpenResty容器
- 了解基本的Docker和Nginx配置
3. OpenResty网络配置调整
3.1 修改OpenResty为桥接网络模式
- 进入1Panel的OpenResty应用设置
- 修改docker-compose.yml文件,将网络模式改为桥接(bridge)
- 修改HTTPS外部映射端口为1443(或其他非443端口)
示例配置:
version: '3'
services:
openresty:
image: openresty/openresty:latest
container_name: ${CONTAINER_NAME}
restart: always
networks:
- 1panel-network
ports:
- "${PANEL_APP_PORT_HTTP}:80"
- "1443:1443"
volumes:
- ./conf/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf
- ./conf/fastcgi_params:/usr/local/openresty/nginx/conf/fastcgi_params
- ./conf/fastcgi-php.conf:/usr/local/openresty/nginx/conf/fastcgi-php.conf
- ./log:/var/log/nginx
- ./conf/conf.d:/usr/local/openresty/nginx/conf/conf.d/
- ./www:/www
- ./root:/usr/share/nginx/html
- /etc/localtime:/etc/localtime
labels:
createdBy: "Apps"
networks:
1panel-network:
external: true
重要说明:
- 改为桥接网络后,反向代理不能使用127.0.0.1:端口的方式
- 需要重建OpenResty容器使配置生效
4. 修改站点监听端口
- 进入站点配置文件
- 将HTTPS监听端口从443改为1443(与外部映射端口一致)
- 可使用Ctrl+F批量替换
- 其他配置保持不变
5. 安装雷池WAF
5.1 添加第三方应用库
根据网络环境选择以下一种方式:
国内网络:
git clone -b localApps https://ghproxy.com/https://github.com/okxlin/appstore /opt/1panel/resource/apps/local/appstore-localApps
cp -rf /opt/1panel/resource/apps/local/appstore-localApps/apps/* /opt/1panel/resource/apps/local/
rm -r /opt/1panel/resource/apps/local/appstore-localApps
国际网络:
git clone -b localApps https://github.com/okxlin/appstore /opt/1panel/resource/apps/local/appstore-localApps
cp -rf /opt/1panel/resource/apps/local/appstore-localApps/apps/* /opt/1panel/resource/apps/local/
rm -r /opt/1panel/resource/apps/local/appstore-localApps
执行完成后,在1Panel应用商店刷新本地应用。
5.2 安装雷池WAF
- 在应用商店中找到雷池WAF并安装
- 等待安装完成
6. 配置雷池WAF
6.1 添加站点
有两种方式:
方式一:直接添加容器端口作为上游
- 雷池WAF监听443端口
- 上传SSL证书
- 配置上游服务为容器端口
方式二:与OpenResty集成(推荐)
- 添加上游服务为:
https://127.0.0.1:1443 - 域名填写与OpenResty站点一致
- 雷池WAF监听443端口
- 上传SSL证书
架构说明:
- OpenResty处理正常网站配置
- 雷池WAF作为下游提供安全防护
7. SSL证书管理
雷池WAF社区版没有证书夹功能,需要手动管理证书更新。
7.1 查找证书文件位置
证书文件位于:
/opt/1panel/apps/local/safeline/safeline/data/resources/nginx/sites-enabled
查看配置文件可获取具体证书文件名,例如:
server {
listen 0.0.0.0:443 ssl;
server_name www.example.com;
ssl_certificate /etc/nginx/certs/agicaikcgbac__.example.com-fullchain.cer;
ssl_certificate_key /etc/nginx/certs/shcvogagbaovga__.example.com.key;
...
}
7.2 自动更新证书脚本
使用acme.sh签发的证书,可以创建以下脚本自动更新:
# 更新雷池WAF证书
cp /root/.acme.sh/*.example.com_ecc/fullchain.cer /opt/1panel/apps/local/safeline/safeline/data/resources/nginx/certs/agicaikcgbac__.example.com-fullchain.cer
cp /root/.acme.sh/*.example.com_ecc/*.example.com.key /opt/1panel/apps/local/safeline/safeline/data/resources/nginx/certs/shcvogagbaovga__.example.com.key
# 同时更新OpenResty证书
cp /root/.acme.sh/*.example.com_ecc/fullchain.cer /opt/1panel/apps/openresty/openresty/www/sites/www.example.com/ssl/fullchain.pem
cp /root/.acme.sh/*.example.com_ecc/*.example.com.key /opt/1panel/apps/openresty/openresty/www/sites/www.example.com/ssl/privkey.pem
7.3 设置计划任务
将上述脚本添加到1Panel的计划任务中,设置定期执行以自动更新证书。
8. 总结
通过以上步骤,我们实现了:
- OpenResty与雷池WAF的集成部署
- 流量路径:用户 → 雷池WAF(443) → OpenResty(1443)
- SSL证书的自动更新机制
这种架构既保留了OpenResty的灵活配置能力,又增加了雷池WAF的安全防护功能,适合生产环境使用。