Nginx规则来阻止特定的URL [英] Nginx Rule to Block Specific URL

查看:1497
本文介绍了Nginx规则来阻止特定的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编写规则以阻止以下请求时需要帮助

Need some help in writing a rule to block the following request

有问题的网址是:

www.somesite.com/catalogsearch/result/?q=downloader

我尝试了以下方法,但这不起作用

I have tried the following, but this does not work

location ^~ catalogsearch/result/?q=downloader {
    deny all;
}

我认为"的是因为?包括问号是将网址视为查询字符串吗?

I "think" the because the ? question mark is included is treating the url as a query string??

致谢

推荐答案

如果只想通过参数q=downloader阻止访问URL www.somesite.com/catalogsearch/result/:

If you want to block access through the parameter q=downloader only at URL www.somesite.com/catalogsearch/result/ :

error_page 418 = @blockAccess;

location /catalogsearch/result {
        if ($args ~* "q=downloader") {
                return 418;
        }
}

location @blockAccess {
        deny all;
}

location /

如果要阻止所有URL的q=downloader参数,只需将下面的代码放在location之前:

If you want to block the q=downloader parameter of all URL's, just put the code below before location:

error_page 418 = @blockAccess;

if ($args ~* "q=downloader") {
    return 418;
}

location @blockAccess {
    deny all;
}

如果您想阻止www.somesite.com/catalogsearch/result/:

If you want to block the www.somesite.com/catalogsearch/result/ :

error_page 418 = @blockAccess;

# Add before "location /"
location /catalogsearch/result {
        return 418;
}

location @blockAccess {
        deny all;
}

这篇关于Nginx规则来阻止特定的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆