How the server responds
[[email protected] blog]# netstat-lntup|grep 80tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5784/nginx
Start the Nginx service, the system listens to the 80 port of this machine (80 port is all the network card of this machine), so as long as the client requests the IP 80 port of any piece of network card, Nginx will respond, the client requests 80 port of any NIC IP, Nginx Service will look at the request message in which there is a call host:www.etiantian.org, Nginx Server received the request message after the request domain name, port, Will find the virtual host from the nginx.conf configuration file, if the client's request message does not have a virtual hostname only 1 IP address name, then the Nginx server can only send the default first virtual host name in the nginx.conf configuration file in response to the message to the client. The first default virtual host named Www.etiantian.org in the article below
That is, if the client directly input nginx IP address, then the NGINX server response message when the default response to the first virtual host name to the client.
[[email protected] conf]# cat nginx.confworker_processes 1;events { worker_connections 1024;} http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name www.etiantian.org; location / { root html/www; index index.html index.htm; } } server { listen 80; server_name bbs.etiantian.org; location / { root html/bbs; index index.html index.htm; } } server { listen 80; server_name blog.etiantian.org; location / { root html/blog; index index.html index.htm; } }}
This article is from the "Sandshell" blog, make sure to keep this source http://sandshell.blog.51cto.com/9055959/1957731
Detailed principle and process of virtual host access based on domain name in combination with HTTP