I have a requirement; any hits with /admin is blocked in the firewall but ppl are accessing it with upper case combinations like /Admin or /adMin or anything like this.
To block admin access for outside, its hard to make firewall rule for all the combinations, hence looking for some method in nginx to block this,
Please note we also need to block the subpaths like /admin/img/one.jpg (subpaths are case sensitive only admin is insensitive). Existing firewall rule is to block all outside access for /admin and allows only VPN access.
Kindly help if more details required I will update this ticket.
You can use a case insensitive regular expression, either using the ~* operator or using a series of character classes.
Any of the following should work:
location ~* ^/admin { return 403; }
if ($request_uri ~* ^/admin) { return 403; }
rewrite ^/[Aa][Dd][Mm][Ii][Nn] /goaway.html redirect;
Each of the above regular expressions match the beginning of the URI, so URIs containing subpaths will also match.
See this document for location, this document for if, and this document for rewrite.