Nginx Rule to Block Specific URL

戏子无情 提交于 2019-12-11 01:14:05

问题


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

The url in question is:

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??

Regards


回答1:


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;
}

Add before 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;
}

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;
}


来源:https://stackoverflow.com/questions/48613517/nginx-rule-to-block-specific-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!