Make nginx return 403 error when accessing non defined sites or direct IP
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.
` server {
listen 80 http2 default_server; listen 443 ssl http2 default_server; server_name _; ssl_certificate /etc/nginx/ssl/default/crt; ssl_certificate_key /etc/nginx/ssl/default/key; return 403;
} `
<- OTHERS ->