How to configure NGINX to returns 404 for non hosted domains
2 minutos de lectura
I had to solve this problem: someone pointed his domain name to the IP of my server, and then by default NGINX returns the 200 code and Success default page for new domain names. So i searched the way to configure NGINX to return only 404 error code when the domain is not hosted in my server. After some attempts i got it run.
Edit the NGINX config file with the IP of your server:
And then put something like this, replacing 22.214.171.124 with your server IP, and the correct SSL certificate files paths. But this paths are setted already in the default file that it was created when installed/configured your NGINX for your hosted domains:
listen 126.96.36.199:80 default;
listen 188.8.131.52:443 ssl http2;
And then restart NGINX service:
sudo service nginx restart
Then if someone configure his domain name to points to your server IP address (it was my case), now your NGINX server will return a 404 code instead of the default 200 "Success" HTML page for new domain names hosted on your server.