1

I saw: http://wellconsidered.be/post/10519707671/node-js-on-nginx and Node.js + Nginx - What now?

But in their tutorials put:

 server_name www.yoursite.com;

or

 server_name yourdomain.com yourdomain;

But in my case I don't have a domain, i have a static IP to my machine in the enterprise (192.168.1.16). I should set the server_name as 192.168.1.16? But anyway I can also set to www.google.com? I cannot understand the restrictions or what exactly does the server_name variable.

Also I see

listen   80;
server_name www.yoursite.com;

Why do I listen to 80 in this case? It's the port of what exactly, of the local server or what?

I imagine nginx should be a global router for the server and every request received at it's static ip (192.168.1.16: don't know the port?? it matters anyway here?) would be redirected to the internal ips, this is why I don't understand why I should define the server_name..

I hope a better explanation for someone that never worked with a server.

I'm very very new to ubuntu and server configuration so this might be a very obvious question.

Community
  • 1
  • 1
Totty.js
  • 15,563
  • 31
  • 103
  • 175

1 Answers1

1

1) The reason for the server_name parameter is that several different domain names can all point to the same IP address. When a browser makes a connection to a URL that contains a domain name, it first does a DNS lookup to find the appropriate IP address. Then it connects to that address and makes an HTTP connection which includes a header consisting of Host: followed by the domain name from the URL. That header tells the server which domain the request was for.

Under normal circumstances, a server won't see a particular domain name in the Host: header unless DNS resolves that domain name to its IP address. Thus if you put "www.google.com" in the server_name field, the only way the server would ever see it is if you edited your hosts file to add an entry for "www.google.com" with your IP address, since that's the first place your OS's DNS resolver will look (of course then your browser, but nobody else's, will always go to your server rather than Google's).

If you don't have a domain name, you can just make something up; the server will never actually see it if you only access it by numeric-IP URLs.

2) 80 is the default port for HTTP servers: unless you explictly specify another port in a URL, the connection will be made to port 80. It's possible for a server to listen to multiple ports, but it's also possible to have multiple servers listening to multiple ports. Thus the server needs to know what ports it's supposed to listen to.

ebohlman
  • 14,795
  • 5
  • 33
  • 35