The relationship between the nginx configuration file and the hosts file

Source: Internet
Author: User
Tags domain name server
The relationship between the nginx configuration file and the hosts file I would like to ask what is the relationship between the ing items in the hosts in windows and the host of the server configured in nginx? When using a browser for access, does the domain name first search in the hosts file and then access resources through an IP address? does nginx not match the request (because it is an IP address )?


Reply to discussion (solution)

Server_name in nginx will also go through hosts to check whether it corresponds. hosts is equivalent to a small domain name server. This should be the case.

If you enter a URL in your browser, you will first check your local hosts file. if there is a ing, you will directly access your web server through the mapped ip address (nginx here) after the request is obtained by nginx, it will check whether the requested domain name matches the servername. if the request matches, it will return content based on the corresponding configuration, if no match is found, the system returns the content based on the default configuration.

What is the relationship between the ing items in hosts in windows and the host of the server configured in nginx? When using a browser for access, does the domain name first search in the hosts file and then access resources through an IP address? does nginx not match the request (because it is an IP address )?




Access resources through ip addresses, but nginx will find the hostname in the request header to match the configuration file needed to process the response.
GET/rabbit/tracking-ad/main. js. map HTTP/1.1 Host: csdnimg.cn // note this. nginx will match servernameConnection: keep-aliveCache-Control: max-age = 0User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36 Accept: */* Referer: unzip gzip, deflate, sdchAccept-Language: zh-CN, zh; q = 0.8

If the request header does not contain a host, nginx will find the configuration for processing the request in sequence. generally, port 80 is enabled by default and will match the configuration in the default configuration.

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.