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?
CodePudding user response:
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.