位置正则表达式返回错误 410?在 Nginx

ale*_*xus 5 nginx

我正在使用nginx-1.6.2,2并且我想返回error 410匹配的 URL /browse.php?u=http,因此诸如此类的请求将获得 410:

162.218.208.16 - - [21/Nov/2014:12:35:40 -0500] "GET /browse.php?u=http%3A%2F%2Fwww.bing.com%2Fsearch%3Fq%3DBroke%2C%2BUSA%2Bfiletype%3Apdf%26first%3D0%26count%3D20%26format%3Drss&b=156&f=norefer HTTP/1.1" 403 570 "http://ww.thespacesurf.com/browse.php?u=http%3A%2F%2Fwww.bing.com%2Fsearch%3Fq%3DBroke%2C%2BUSA%2Bfiletype%3Apdf%26first%3D0%26count%3D20%26format%3Drss&b=156&f=norefer" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)"
Run Code Online (Sandbox Code Playgroud)

我真的不需要regex,所以像这样,但它不起作用:

location = /browse.php?u=http {
        return 410;
}
Run Code Online (Sandbox Code Playgroud)

几天后,我grep -c410/var/log/nginx-access.log

$ bzip2 -cd /var/log/nginx-access.log.0.bz2 | grep -c ' 410 '
5665
$ 
Run Code Online (Sandbox Code Playgroud)

这让我感到温暖和模糊)再次感谢!

noc*_*kin 0

这是因为 location 是/browse.php,而不是您指定的位置。

有几种方法可以做到这一点。例如,类似这样的事情应该做:

location = /browse.php {
        if ($query_string ~ ^u=http) {
                return 410;
        }
}
Run Code Online (Sandbox Code Playgroud)

PS:或者用if~*代替不区分大小写。~u=http