首页 > 数据库 > mysql教程 > 关于nginx配置中的多个if的匹配规则

关于nginx配置中的多个if的匹配规则

WBOY
发布: 2016-06-07 15:05:52
原创
1930 人浏览过

location ~ /bb { if ( $ args ~ "_kw=[\w]+" ) { access_log logs/kw ; access_log logs/all ; } if ( $ args ~ "(_pg=[\w]+|_pc=[\w]+)" ) { access_log logs/pg ; access_log logs/all ; } if ( $ args ~ "_kw=[\w]+.*(_pg=[\w]+|_pc=[\w]+)" ) { access_

<span>location ~ /bb {<br><br>                <span>if</span> <span>(</span><span>$</span>args ~ <span>"&_kw=[\w]+"</span><span>)</span><span>{</span><br>                        access_log logs/kw<span>;</span><br>                        access_log logs/all<span>;</span><br>                }<br><br><br>                <span>if</span> <span>(</span><span>$</span>args ~ <span>"(&_pg=[\w]+|&_pc=[\w]+)"</span><span>)</span><span>{</span><br>                        access_log logs/pg<span>;</span><br>                        access_log logs/all<span>;</span><br>                }<br><br><br>                <span>if</span> <span>(</span><span>$</span>args ~ <span>"&_kw=[\w]+.*(&_pg=[\w]+|&_pc=[\w]+)"</span><span>)</span><span>{</span><br>                        access_log logs/kw<span>;</span><br>                        access_log logs/pg<span>;</span><br>                        access_log logs/all<span>;</span><br>                }<br><br><br>                access_log logs/all<span>;</span><br><br>        }<br></span>

<span><br></span>


http://1.1.1.1/bb?&_kw=1777&_pg=-1&_pc=1

对于上面的配置,访问上面的url时,即匹配第一个if(因为\w为[a-zA-Z0-9_],不包含“-”,又匹配最后一个if,后面的if生效。(匹配多个if的args,后面的if生效)


验证:


<span><br>         location ~ /bb {<br> <br>                 <span>if</span> <span>(</span><span>$</span>args ~ <span>"&_kw=[\w]+"</span><span>)</span><span>{</span><br>                         access_log logs/kw<span>;</span><br>                 }<br> <br>                 <span>if</span> <span>(</span><span>$</span>args ~ <span>"&_kw=[\w]+"</span><span>)</span><span>{</span><br>                         access_log logs/kw111<span>;</span><br>                 }<br> }</span>


我没有在nginx的文档中找到明确的有关于多个if生效的规则说明,如果谁知到在什么地方,请告诉我,谢谢。


另:关于nginx location(不是多个if)匹配规则

http://wiki.nginx.org/NginxHttpCoreModule#location

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板