S
S
supspec2016-10-14 06:25:27
Nginx
supspec, 2016-10-14 06:25:27

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

2 answer(s)
M
Mysterion, 2016-10-14
@Mysterion

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

And the address file is in the format:
ip key
nginx.org/en/docs/http/ngx_http_geo_module.html

L
Lynn "Coffee Man", 2016-10-14
@Lynn

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 question

Ask a Question

731 491 924 answers to any question