I was running into an issue where when people would go to the IP of my server or a domain was pointed at my server and the domain wasn’t configured in NGINX it would for some reason redirect to one of my domains when I didn’t want it to. Below is the config block that I added to a file. This make NGINX return a 403 error when accessing the server via IP or an reconfigured domain.
I had defined http2; depending on your version of NGINX you might have to remove the HTTP2 from the block.
listen 80 http2 default_server;
listen 443 ssl http2 default_server;