问题
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