Nginx to prohibit use of IP access Web site configuration Instances _nginx

Source: Internet
Author: User

Because of the record in China, all servers are prohibited from using IP to access the site. Otherwise, if you allow the use of IP access to the site, that casual resolution of a domain name to the IP, access to the domain name can open the site. This is a great risk! Nginx can be very convenient to solve this problem, small rookie to discuss with you.

Because of the record in China, all servers are prohibited from using IP to access the site. Otherwise, if you allow the use of IP access to the site, that casual resolution of a domain name to the IP, access to the domain name can open the site. This is a great risk! Nginx can be very convenient to solve this problem, small rookie to discuss with you.

As a configuration entry below, you can set up to allow access to the Web site using IP.

Copy Code code as follows:

server {
Listen 80;
SERVER_NAME "";
}

This is equivalent to binding an empty host header, so any host head, as long as the IP can open the site.

If you need to nginx prohibit the use of IP access sites, you can define the following hosts to discard these requests:

Copy Code code as follows:
server {
Listen 80;
SERVER_NAME "";
return 444;
}

Here, we set the host name to be an empty string to match a request that does not define the "host" header, and returns a Nginx-specific, non-HTTP standard return code 444, which can be used to close the connection.

Starting with version 0.8.48, this has become the default setting for host names, so you can omit server_name "", which is the following configuration:

Copy Code code as follows:
server {
Listen 80;
return 444;
}

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.