Deny Hosts Using Nginx
I was noticing my nginx log file fill up with requests for a site who had misconfigured their DNS. Normally I wouldn’t worry about it, but it became quickly evident that the domain was used for an image server for a parent site. There were thousands of RPS that I really didn’t need.
All I did was add the following expression to my nginx.conf file.
1Server { 2 ...snip... 3 ## Deny illegal Host headers 4 if ($host !~* ^(mydomain.com|www.mydomain.com)$ ) { 5 return 444; 6 } 7 ...snip... 8} Now if you look at the code, you may be thinking “But Jared, what is a 444 error? That is totally not valid bro.” And indeed, you are correct. But here is what the nginx documentation has to say about it.
_“Furthermore, nonstandard code 444 closes the connection without sending any headers.……