nginx正则测试工具

整理了一些方便nginx 正则测试的工具

使用官方提供的一个基于php 的环境

nginx-regex-tester

使用pcretest

对于alpine docker 镜像可以通过安装pcre-tools 解决

参考集成环境

nginx-regex-tester我已经构建过一个docker镜像,以下是pcretest的

  • dockerfile
FROM nginx:alpine
LABEL author="dalongrong"
RUN set -x \
    && /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories \
    && apk update && apk add --no-cache pcre-tools 
COPY  --from=yaronpr/gotty /usr/local/bin/gotty /usr/local/bin/gotty
EXPOSE 8080
COPY entrypoint.sh /entrypoint.sh 
RUN chmod +x /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]

entrypoint.sh

#!/bin/sh
nohup gotty -w sh &
nginx -g "daemon off;"

pcretest 简单说明

第一行写 /中间加上正则表达式/
第二行写 要匹配的字符
结果说明:
0表示匹配到的所有内容
1最后表示每个位置匹配到的内容

集成环境docker-compose

  • docker-compose 文件
 
version: "3"
services:
    nginx-test:
      build: ./
      image: dalongrong/nginx-pcretest
      ports: 
      - "80:80"
    nginx-regex-test:
      image: dalongrong/nginx-regex-tester_regextester:latest
      ports: 
      - "8080:80"

golang supervisord 版本的pcretest dockerfile

 
FROM nginx:alpine
LABEL author="dalongrong"
RUN set -x \
    && /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories \
    && apk update && apk add --no-cache pcre-tools 
COPY  --from=yaronpr/gotty /usr/local/bin/gotty /usr/local/bin/gotty
COPY --from=ochinchina/supervisord:latest /usr/local/bin/supervisord /usr/local/bin/supervisord
EXPOSE 8080 80
COPY supervisor.conf /etc/supervisor.conf
CMD ["/usr/local/bin/supervisord","-c","/etc/supervisor.conf"]

supervisor.conf

[program:website]
command = nginx -g "daemon off;"
[inet_http_server]
port = :9001
[program:gotty]
command = gotty -w sh

说明

以上运行集成了gotty一个很不错的webconsole 工具,对于开发环境还是很不错的选择,可以方便测试,同时我也已经制作了
一个集成好的docker镜像dalongrong/nginx-pcretest 可以方便使用

参考资料

https://www.cnblogs.com/rongfengliang/p/13150534.html
https://github.com/nginxinc/NGINX-Demos/tree/master/nginx-regex-tester
https://github.com/yudai/gotty
https://github.com/rongfengliang/nginx-pcretest-docker

posted on   荣锋亮  阅读(1390)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2018-12-11 Gource 方便的软件版本可视化录制工具
2018-12-11 tailor multi fragment && cutom-amd script demo 说明
2018-12-11 使用tailor 轻松方便的集成web 框架react&&vue
2017-12-11 apache phoenix 安装试用

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示