起因
nginx 測試基本都是本地起一個 nginx 服務,然后修改 conf 配置文件進行測試,那么,有沒有更方便快捷的方法呢?
雖然網上有很多正則表達式的網站,但是因為 nginx 和這些網站的正則表達式引擎略有不同,所以很多在線測試的結果是不准確的。
方法
nginx 官方提供了一個基於 php 編寫的正則測試器 nginx-regex-tester,可以用 docker-compose 直接啟動
測試成功截圖;Result: Match found

測試失敗截圖:Result:Match not found

注意問題:
如果你在 docker-compose up -d
很慢,主要是因為 Dockerfile 的 nginx 鏡像使用的國外源
- 確認 nginx 是什么系統,在 dockerfile 加入這兩句去判斷
RUN cat /etc/issue
RUN cat /etc/os-release
- 我剛確認用的是
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
如圖所示;
