Let's take a look at Nginx's default virtual host when a user accesses via IP or through an unnamed domain name (such as when someone points his own domain name to your IP) the key point is to add this line to the server's settings:
The following default
argument indicates that this is the default virtual host.
Nginx prohibit IP access to this setting is useful.
For example, when other people visit your website via IP or unknown domain name, you want to prohibit the display of any valid content, you can return 500 to him. At present, many computer rooms are required to shut down the main web site host head, to prevent the record of the domain name pointed over to cause trouble.
You can set it this way:
server { listen default; return 500;
You can also collect these traffic, import to their own website, as long as the following jump settings can be:
server { listen default; Rewrite ^ (. *) http://www.mydomain.com permanent;
After setting up, it is not possible to access the server through IP, but when server_name
a number of domain names are followed when they should be used, one of the domain names cannot be accessed
The settings are as follows:
server { listen; server_name www.abc.com abc.com }
Before the change, through the server_name www.abc.com abc.com can access the server, add nginx prohibit IP access settings, through the abc.com can not access the server, www.abc.com access, with Nginx -t
The instrumentation profile prompts warning:
[Warn]: Conflicting server name "ABC.com" on 0.0.0.0:80, ignored the configuration file/usr/local/webserver/ nginx/conf/ nginx.conf syntax is OK configuration File/usr/local/webserver/nginx/conf/nginx. Conf Test is successful
Finally passed in listen 80 default;
after the additional server_name _;
solution
The form is as follows:
#禁止IP访问 Server { listen default; server_name _; server_name www.abc.com abc.com return 500;
In this way, the server can be accessed through abc.com.
Summarize
OK, the above is CentOS under Nginx prohibit IP access to all the content, I hope the content of this article for everyone's study or work can bring certain help, if there are questions you can message exchange, thank you for your support cloud habitat community.