原文链接: 1Panel上的长亭雷池WAF搭配openresty的用法

前言

最近把面板换成了国内公司出的然而开源的1panel,跑容器也是挺合乎心里需要的,

主界面也挺洁净整洁。看到第三方利用库有个收费WAF,而后又上了开源了但没齐全开源的长亭雷池WAF

记录一下在同一台机子上长亭雷池WAF搭配默认openresty的用法。

1. 调整openresty容器网络

须要将openresty批改为桥接网络模式。且批改https内部映射为其余端口如1443

留神:改桥接端口之后,反向代理的思路就和应用Nginx Proxy Manager一样了,

  • 不能写127.0.0.1:端口来反向代理了。

点击利用参数批改docker-compose.yml,重建openresty

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

2. 批改站点监听端口

站点失常配置,开启https啥的。

进入站点文件配置,批改https监听端口为1443,与内部端口统一。

能够按Ctrl F批量替换。其余配置能够不必动。

3. 雷池WAF增加站点

3.1 增加第三方库

而后利用商店装置雷池WAF

  • 1Panel 利用商店的非官方利用适配库

以默认1Panel装置在/opt/门路下为例子,如果不是按需批改以下。

3.1.1 国内网络

1panel打算工作类型Shell 脚本的打算工作框里,增加并执行以下命令,或者终端运行以下命令,

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

而后利用商店刷新本地利用即可。

3.1.2 国际互联网络

1panel打算工作类型Shell 脚本的打算工作框里,增加并执行以下命令,或者终端运行以下命令,

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

而后利用商店刷新本地利用即可。

3.2 雷池WAF增加站点

  • 一种是间接增加一般容器端口做上游,雷池WAF监听443端口,上传证书即可。
  • 另一种就是搭配openresty

具体形式是如下:

  • 增加上游服务为https://127.0.0.1:1443
  • 域名填写与openresty站点统一
  • 雷池WAF监听443端口
  • 失常上传证书

这样子就失常增加了,失常网站配置还是由openresty 提供,雷池WAF做个上游。

4. 对于SSL证书继续

雷池WAF社区版本这边还没证书夹,每增加一个站点就须要上传证书。

而后命名也是随机产生。想要使拜访站点的SSL证书失常,还是得一直将签发的证书将旧证书文件替换掉。

这里用acme.sh签发的来替换。

具体的对应站点SSL证书对应能够查看配置获取。
具体文件门路在相似如下文件夹里

/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;    location = /forbidden_page {        internal;        root /etc/nginx/forbidden_pages;        try_files /default_forbidden_page.html =403;    } 

如上所示则能够取得证书文件文件名如下:
– agicaikcgbac__.example.com-fullchain.cer
– shcvogagbaovga__.example.com.key

则替换雷池WAF证书的命令能够写为

# safeline-www.example.comcp /root/.acme.sh/*.example.com_ecc/fullchain.cer /opt/1panel/apps/local/safeline/safeline/data/resources/nginx/certs/agicaikcgbac__.example.com-fullchain.cercp /root/.acme.sh/*.example.com_ecc/*.example.com.key /opt/1panel/apps/local/safeline/safeline/data/resources/nginx/certs/shcvogagbaovga__.example.com.key

也能够棘手替换一下openresty创立的站点的证书

# openresty-www.example.comcp /root/.acme.sh/*.example.com_ecc/fullchain.cer /opt/1panel/apps/openresty/openresty/www/sites/www.example.com/ssl/fullchain.pemcp /root/.acme.sh/*.example.com_ecc/*.example.com.key /opt/1panel/apps/openresty/openresty/www/sites/www.example.com/ssl/privkey.pem

而后将这两个替换证书的命令增加到打算工作列表就行了。