整理了一些方便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"
- 使用
nginx-regex-tester http://localhost:8080/regextester.php
pcretest http://localhost:9090 (webconsole 操作)
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