Answer the question
In order to leave comments, you need to log in
How to teach nginx to return 404 instead of 403 when blocking a client by ip?
Good afternoon, there is a server with nginx and a bunch of sites. The task is to block spammers on all sites by ip range (resolved through the ngx_http_access_module at the http level) and give them not 403 Forbidden (in this case, the spammer simply changes the proxy), but 404 Not Found.
It is also desirable to have a solution at the http level.
Answer the question
In order to leave comments, you need to log in
I would put somewhere a file with a list of addresses that need to be blocked, and in the nginx config:
map $geo{
include path/to/file;
}
server {
if ($geo) {
return 404;
}
}
Write alongside:
But be aware that this will work for all 403 responses from nginx.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question