nginx method to close the default site

  • 2020-05-06 12:05:55
  • OfStack

If you don't take action when someone else directs a spam domain name to your server, the consequences will be dire.

Domestic machine room generally requires the site master to close the empty host head, to prevent the registration of the domain name to cause trouble.

The default Nginx virtual host allows users to access IP, or your VPS or server, through an unconfigured domain name (such as someone who points his domain name to your ip).

By default, simply resolving the domain name to IP of VPS gives you access to VPS, where lnmp is installed.

If you want to avoid this situation, you can modify nginx.conf by changing the default virtual host to the following to block unbound domain access:

 
server { 
listen 80 default; 
return 500; 
} 

You can also collect this traffic and direct it to your website by simply making the following jump Settings:
 
server { 
listen 80 default; 
rewrite ^(.*) http://jb51.net permanent; 
} 

In the same way, access is not allowed through IP, which can be written as:
 
server { 
listen 80 default; 
server_name _; 
return 500; 
} 


Related articles: