【Nginx】 正则在线测试


起因

nginx 测试基本都是本地起一个 nginx 服务,然后修改 conf 配置文件进行测试,那么,有没有更方便快捷的方法呢?

虽然网上有很多正则表达式的网站,但是因为 nginx 和这些网站的正则表达式引擎略有不同,所以很多在线测试的结果是不准确的。

nginx使用的是 PCRE官方文档介绍

方法

nginx 官方提供了一个基于 php 编写的正则测试器 nginx-regex-tester,可以用 docker-compose 直接启动

测试成功截图;Result: Match found

测试失败截图:Result:Match not found

注意问题:

如果你在 docker-compose up -d 很慢,主要是因为 Dockerfile 的 nginx 镜像使用的国外源

  1. 确认 nginx 是什么系统,在 dockerfile 加入这两句去判断
RUN cat /etc/issue
RUN cat /etc/os-release
  1. 我刚确认用的是 debian buster 系统,所以直接更换为清华源就好了,
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free \n\
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free \n\
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free \n\
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free" > /etc/apt/sources.list

如图所示;

https://www.nginx.com/blog/regular-expression-tester-nginx/


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM