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
Kenyataan:Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn