在nginx中,有没有一种方法可以根据推荐来拒绝访问网站的特定部分?
基本上是试图阻止从2个引用域名访问2个目录。
下面是我使用的代码:
if ( ($http_referer ~* (badomain1.com|badomain2.com)) &&
($request_uri ~* (directory1/|directory2/))
) {
return 403;
}但nginx失败并返回错误:
emerg: invalid condition“($http_referer位于/usr/local/nginx/conf/nginx.conf:88配置文件/usr/local/nginx/conf/nginx.conf测试失败
任何帮助都将不胜感激。
谢谢。
发布于 2011-12-16 08:55:15
我认为你需要像这样转义点:。
然后返回444,它是nginx内部的,表示根本不应答。
if ($http_referer ~* (babes|click|diamond|forsale|girl|jewelry|love|nudit|organic|poker|porn|poweroversoftware|sex|teen|video|webcam|zippo) ) {
return 444;
}发布于 2011-12-16 15:29:30
Nginx "if“语句与PHP等脚本语言中的"if”语句不同。它只是一个重写指令。
你不能有像这样的东西
if *expression1* OR *expression2* then
*code*
end你需要做的是
if *expression1* then
*Rewrite Directive Only*
end
if *expression2* then
*Rewrite Directive Only*
end去做
if *expression1* AND *expression2* then
*code*
end你需要做的是
if *expression1* then
set $myVar X;
end
if *expression2* then
set $myVar $myVarX;
end
if $myVar = XX then
*Rewrite Directive Only*
end"Return“和"Set”是有效的重写指令。
我使用类似的设置来过滤请求,并通过Lua模块使用Lua对其进行评估,从而实际上将其提升了一个级别。
if (*expression1* OR *expression2*) AND (*expression3* OR *expression4*) then
*Complex Code*
endhttps://stackoverflow.com/questions/8524071
复制相似问题