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.