The relationship between Nginx configuration file and Hosts file

Source: Internet
Author: User
Tags domain name server
I would like to ask what is the relationship between the mappings in the hosts in Windows and the host of the server configured in Nginx? When using the browser to access, whether the domain name first in the Hosts file to find, and then through the IP address to access resources, then Nginx will not match the request (because it is an IP address)?


Reply to discussion (solution)

Nginx in the server_name will also go through the hosts, see if the corresponding, the hosts is equivalent to a small domain name server. That should be it.

You enter a URL in the browser will check your local hosts file if there is a mapping, directly through the mapped IP access to your Web server (this is Nginx) when the request was received by Nginx He's going to check it. The requested domain name and servername are matched, and the match is returned based on the corresponding configuration, and the content is returned according to the default configuration if no match is reached.

I would like to ask what is the relationship between the mappings in the hosts in Windows and the host of the server configured in Nginx? When using the browser to access, whether the domain name first in the Hosts file to find, and then through the IP address to access resources, then Nginx will not match the request (because it is an IP address)?




The resource is accessed through IP, but Nginx will find the hostname inside the request header to match the one that needs to handle the response.
Get/rabbit/tracking-ad/main.js.map http/1.1host:csdnimg.cn//Note this, Nginx will be based on this matching 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.36accept: */*referer:http:// Bbs.csdn.net/forums/phpaccept-encoding:gzip, deflate, sdchaccept-language:zh-cn,zh;q=0.8

If there is no host in the request header, Nginx will also find the configuration to handle the request in order, the general default port 80 is open and will match to the default configuration.

  • 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.