上篇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.没有修饰符的匹配
在使用时的顺序
没有修饰符的写在最前面
~
~*
精确匹配最后