Disable the nginx null header to prevent the nginx null header and malicious domain name pointing

  • 2020-05-12 06:50:59
  • OfStack

The virtual host in nginx's default configuration allows users to access it through IP, or through an unset domain name (such as someone who maliciously points his own domain name to your ip)
This is because the server area in the default configuration has this 1 line:
listen 80 default;
The default parameter in the back indicates that this is the default virtual host and accepts all domain names pointing to it
For example, if someone visits your website through ip or an unknown domain name, and you want to block the display of any valid content, you can return him 500.


server {
listen 80 default;
server_name _;
return 500;
}

You can also collect this traffic and import it to your own site by doing the following:


server {
listen 80 default;
rewrite ^(.*) //www.ofstack.com permanent;
}

If there are multiple IP servers, only 1 IP is blocked:
Try this:


server {
listen *:80 default;
server_name _;
return 500;
}

Try again when you can't:


server {
listen *:80;
server_name _;
return 500;
}

After using the null host header, PHPmyadmin will not be accessible after adding a level 2 domain name to point to the phpmyadmin directory.


Related articles: