if I have an entry in my hosts file ,and also the hostname is in the server block of the nginx configure file ,I wonder which file is applied first and does what specific,could someone tell me ?
如果我的hosts文件中有一个条目,并且主机名也在nginx配置文件的服务器块中,我想知道哪个文件首先被应用并且具体是什么,有人可以告诉我吗?
1 个解决方案
#1
The hosts file is used by your OS to resolve hostnames to IPs and is usually evaluated first (can be customized - at least on unix based OS). If you tell an application to look for some host, e.g. www.example.com, it looks up the name in the hosts file and uses the IP to connect to that host. In case the hostname can't be found in the file, it will usually ask the configured DNS servers for it.. See Hosts File and DNS for more info.
您的操作系统使用hosts文件将主机名解析为IP,并且通常首先对其进行评估(可以自定义 - 至少在基于unix的操作系统上)。如果您告诉应用程序寻找某个主机,例如www.example.com,它在hosts文件中查找名称并使用IP连接到该主机。如果在文件中找不到主机名,它通常会向配置的DNS服务器询问它。有关详细信息,请参阅主机文件和DNS。
The hostname in the server block on the other side is used by nginx to determine the appropriate action to be taken. nginx evaluates the HOST header in the request and tries to match it against the values configured in the server_name
variables in each block. See Server names and How nginx processes a request.
nginx使用另一侧服务器块中的主机名来确定要采取的适当操作。 nginx评估请求中的HOST头,并尝试将其与每个块中server_name变量中配置的值进行匹配。请参阅服务器名称和nginx如何处理请求。
#1
The hosts file is used by your OS to resolve hostnames to IPs and is usually evaluated first (can be customized - at least on unix based OS). If you tell an application to look for some host, e.g. www.example.com, it looks up the name in the hosts file and uses the IP to connect to that host. In case the hostname can't be found in the file, it will usually ask the configured DNS servers for it.. See Hosts File and DNS for more info.
您的操作系统使用hosts文件将主机名解析为IP,并且通常首先对其进行评估(可以自定义 - 至少在基于unix的操作系统上)。如果您告诉应用程序寻找某个主机,例如www.example.com,它在hosts文件中查找名称并使用IP连接到该主机。如果在文件中找不到主机名,它通常会向配置的DNS服务器询问它。有关详细信息,请参阅主机文件和DNS。
The hostname in the server block on the other side is used by nginx to determine the appropriate action to be taken. nginx evaluates the HOST header in the request and tries to match it against the values configured in the server_name
variables in each block. See Server names and How nginx processes a request.
nginx使用另一侧服务器块中的主机名来确定要采取的适当操作。 nginx评估请求中的HOST头,并尝试将其与每个块中server_name变量中配置的值进行匹配。请参阅服务器名称和nginx如何处理请求。