nginx之增加echo模块以及修饰符的使用




上篇nginx

nginx增加echo模块

[root@192 ~]# nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log





[root@192 ~]# cd /usr/src/
[root@192 src]# tar xf v0.61.tar.gz         ##要与nginx-1.18.0同一目录下




[root@192 src]# cd nginx-1.18.0
./configure --prefix=/usr/src/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log \
--add-module=../echo-nginx-module-0.60


[root@192 src]#make




备份
[root@192 nginx-1.18.0]# cp /usr/local/nginx/sbin/nginx /tmp/




覆盖
[root@192 nginx-1.18.0]# cp ./objs/nginx /usr/local/nginx/sbin/nginx 




成功
[root@192 nginx-1.18.0]# nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: ....... --add-module=../echo-nginx-module-0.61


常用修饰符说明

修饰符功能
=精确匹配
~正则表达式模式匹配,区分大小写
~*正则表达式模式匹配,不区分大小写
=精确匹配
^~前缀匹配,类似于无修饰符的行为,也是以指定模块开始,不同的是,如果模式匹配,那么就停止搜索其他模式了,不支持正则表达式
@定义命名location区段,这些区段客户端不能访问,只可以由内部产生的请求来访问,如try_files或error_page等

1.没有修饰符


location  /zyy {
        echo "111";
       }

在这里插入图片描述
没有修饰符,只要开头是zyy,后面不管接什么,都可以匹配到


2. =:表示精确匹配


 location = /zyy {
        echo "222";
       }

在这里插入图片描述
能匹配到
http://192.168.30.244/zyy

http://192.168.30.244/zyy?p1=1111


不能匹配到
http://192.168.30.244/zyy/


精确匹配开头结尾定死了(zyy),只能是这个,但可以接参数



3. ~:表示指定的正则表达式要区分大小写

将 ~ 放到精确匹配后面


location = /zyy {
        echo "222";
       }

       location ~ ^/zyy$ {
        echo "333";
       }


不难看出,精确匹配的优先级要比 ~ 要高,所以为了试验效果我们把精确匹配放到后面并且注释

location ~ ^/zyy$ {
        echo "333";
       }

在这里插入图片描述
能匹配到
http://192.168.30.244/zyy

http://192.168.30.244/zyy?P1=1111

不能匹配到
http://192.168.30.244/zyy1

http://192.168.30.244/zyy/

http://192.168.30.244/zyy/zyy

http://192.168.30.244/ZYY


~ 结尾后可以接参数,也确实不能区分大小写



4. ~*:表示不区分大小写正则表达式

把 ~* 放在 ~ 后面


      location ~ ^/zyy$ {
        echo "333";
       }

       location ~* ^/zyy$ {
        echo "444";
       }

在这里插入图片描述

可以看出 ~* 与 ~ 优先级相同,为了试验效果,将 ~ 放在 ~* 后面

location ~* ^/zyy$ {
        echo "444";
       }

       location ~ ^/zyy$ {
        echo "333";
       }

在这里插入图片描述
可以匹配到
http://192.168.30.244/ZYY

http://192.168.30.244/zyy

http://192.168.30.244/zyy?p1=1111

不能匹配到
http://192.168.30.244/zyy1

http://192.168.30.244/zyy/

http://192.168.30.244/zyy/zyy

~*后面可以接参数,可以区分大小写

修饰符优先级

1.= 精确匹配

2.~ 与 ~* 正则表达式匹配(这两个,根据位置来决定优先级)

3.没有修饰符的匹配


在使用时的顺序
没有修饰符的写在最前面
~
~*
精确匹配最后

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值