简体   繁体   中英

How does nginx virtualhosts know the domain?

Hello stackoverflow community!

How does nginx know from which domain the url comes from in order to serve the right page? I tried adding the domain and the full url to the Referer header but that did not work. Is there any way to access the ip of the server and with the right request get a website?

Nginx knows which domain to serve by looking at the Host HTTP header from the request. For example, if you have a server with several vhosts (assuming domain1.com and domain2.com ), you can get root HTML page from your vhosts using the following curl commands:

curl -H 'Host: domain1.com' <server_ip>

and

curl -H 'Host: domain2.com' <server_ip>

Also, for every combination of IP and port on which nginx is listening, one of the vhosts will act as the default one. See How nginx processes a request official documentation page (or this answer) for more details on how the default vhost is selected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM