军哥,您好,编程的问题。
在conf文件里,我想同时满足二个条件if ( $http_user_agent ~* "compatible; MSIE 6.0; Windows NT 5.1; SV1;"|$ http_referer ~* "news") {
return 403;
}
禁止ie6的用户访问包含news关键词的url
同时满足这二个条件的才生效,但是我这样写报错。军哥能否帮我纠正一下。很重要。谢谢。 $http_referer是记录从哪个地址过来的
$request 才是用户访问的url
同时满足是与运算用&
军哥好,语法有错误。
if ( $http_user_agent ~* "compatible; MSIE 6.0; Windows NT 5.1; SV1;" & $request~* "news") {return 403;
}
这样写会报错,麻烦再帮我看看。
/usr/local/nginx/sbin/nginx -t
nginx: unexpected "&" in /usr/local/nginx/conf/sitestar.conf:10
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed if ( $http_user_agent ~* "compatible; MSIE 6.0; Windows NT 5.1; SV1;") && ( $request~* "news" ) {
这样试试
军哥。改成这样还不行,麻烦再帮我看一下。万份感谢了啊。
# /etc/init.d/nginx restartRestarting nginx daemon: nginxnginx: invalid condition "$http_user_agent " in /usr/local/nginx/conf/sitestar.conf:10
nginx already running.
军哥。改成这样还不行,麻烦再帮我看一下。万份感谢了啊。
if ( $http_user_agent ~* "compatible; MSIE 6.0; Windows NT 5.1; SV1;") && ( $request~* "news" ) {
return http://www.weimeigu.com/tip/;
} 看了一下nginx的if判断貌似不支持与或运算也不支持if语句嵌套
那就
set $rule 0;
if ($request~* ’news‘)
{
set $rule "${rule}1";
}
if ($http_user_agent ~* 'MSIE 6')
{
set $rule "${rule}2";
}
if ($rule = "012")
{
deny all;
}
这样试试看吧 万份感谢了
页:
[1]