【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