Anything that opens my server by IP address, or with a host name I never configured, ends up in whichever server block nginx treats as the default. I would rather have that request go nowhere.
nginx chooses a server block by looking at the Host header. If the value matches no server_name, or the header is missing, the request goes to the default server of that port. The default_server parameter on listen makes that choice explicit.
The documentation shows a server that drops requests without a Host header: an empty server_name and return 444. Combining it with default_server is my own reading of the same docs, so test it:
server {
listen 80 default_server;
server_name "";
return 444;
}
444 is a non-standard nginx code. It closes the connection without sending any response. The docs also mention that since version 0.8.48 an empty server name is the default, so the server_name "" line can be left out; I keep it because it makes the intent visible.
Your real sites stay untouched as long as each has its own server block with proper server_name values on the same port. Requests for example.com go to its block, and requests like http://192.168.1.x/ or a random name pointing at your IP are closed without an answer.
The caveats are about scope. This example is for port 80. The docs describe the default server as a property of each listen port, so if you also serve HTTPS you need a matching catch-all on that port, and I did not verify what that block needs for the certificate part, so check the nginx docs for your setup. Also keep in mind that any site you only reach by IP address will stop answering; if you use that for a quick test, give it its own server name first.
Run nginx -t and reload as usual, then try curl -i http://192.168.1.x/ against the server and expect an empty reply.
Further reading: How nginx processes a request
Going deeper: Guide: fix a 502 Bad Gateway in Nginx Proxy Manager, with a checklist that finds the cause