In this tutorial it is written that after matching against the listen directive, nginx will match agains the server_name directive, which can be either an ip adress or a domain name.

But how will it ever be called when you use a domain name? When I go to my browser and write http://myserver/, this will go the DNS server of my ISP and will tell me that there is no http://myserver/ anywhere to be found.

How does it work?


When you type http://myserver/ in your browser, you will ask the DNS server to resolve name myserver to IP address. Then, the browser will connect to one of the returned IP address(es).

The name myserver will be passed along with HTTP request as Host: myserver header. This is how things work generally not specific to nginx.


There is a file, /etc/hosts , you need to add your domain name there and the IP address corresponding to it.

sudo vim /etc/hosts

(vim or your text editor)

hosts file will open. nagios.monitor.com localhost www.netdatamonitor.com  netdatamonitor.com       www.newgmap.com
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

( is my pc's IP)

This is my file. You should add your domain name there and it should work then if you dont have any other issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.