if ip banned make nginx return 444 (close connection without any response)

I use this to ban specific IP addresses

geo $bad_user {
    default 0;
    xx.xx.xx.xx/32 1;
}

server {
    ...
    
    location / {
        if ($bad_user) {
            return 444;
        }
        
        try_files  $uri $uri/ /index.php?$query_string;
    }
}

But how is it possible to make nginx return 444 if the PHP script returns HTTP 444?

http_response_code(444);
exit;

How it is possible to listen for a HTTP 444 in the nginx location scope?

I want nginx to “hang up” without sending anything in response

location / {
    if ($bad_user) {
        return 444;
    }
    
    if (php script sends HTTP 444) {
        return 444;
    }

    try_files  $uri $uri/ /index.php?$query_string;
}

Read more here: Source link