nginx only allows access to the domain name, ip ban prohibiting access to other domain names

Background:
Why ban ip access pages?
This is done to avoid other people have not filed their own DNS server to IP, which causes the server to be off the network, we can use the ip access by prohibited methods to prevent such things happened.

Solution:
Here nginx.conf modify the configuration file describes two methods:
1) the following is inserted in a regular period in the server:
the listen 80;
server_name www.yuyangblog.net;
IF ($ Host = 'www.yuyangblog.net') {!
   403 return;
}


2) adding a server
newly added server, so return to 403 _ (new note is not modified based on the original server)
server {
  the listen 80 default;
  server_name _;
  return 403;
}
originally inside server insert:
the listen 80;

server_name  www.yuyangblog.net;

 

effect:

After the setup is successful, you can only access the site with a domain name, you can not use the ip visit.

 

 

 

 

Examples of configuration:

[Root @ weifeng conf.d] # cat weifeng.conf

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

 

 

Guess you like

Origin www.cnblogs.com/mafeng/p/11671793.html