Detailed CentOS under Nginx How to prohibit IP access _linux

Source: Internet
Author: User
Tags centos

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.