How can I tell nginx to silently ignore requests that do not match and allow them to time out instead of giving 404

I have a server block that listens for 80 port requests for a specific server name along with some location directives. How can I get nginx to process any request that does not match, as if it did not receive it, which allows it to time out? These requests are currently being processed with a 404 error

+6
source share
2 answers

There is a way to ignore every request and tell nginx nothing to respond:

server { listen 80 default_server; return 444; } 

Documented here: http://nginx.org/en/docs/http/ngx_http_rewrite_module.html

Custom code 444 closes the connection without sending a response header.

+2
source

I assume that you are trying to reject malicious requests. Something like this might work (unverified).

Configure the server by default (it catches any requests that do not match the name of the existing server), and then redirects the client back to itself:

 server { listen 80 default_server; rewrite ^ http://127.0.0.1/; } 

You will need to configure a similar catch-all for invalid locations inside valid server blocks. There may be more headaches than you want.

I do not know how realistic this would be in practice. It might be better to consider fail2ban or some other tool that can track your logs and ban clients on the firewall.

0
source

Source: https://habr.com/ru/post/920788/


All Articles