Nginx Server : Desired Domain Name on Local Host

Francis Daly francis at daoine.org
Sat Jun 16 13:49:55 UTC 2012


On Sat, Jun 16, 2012 at 06:38:53PM +0530, Chetan Patil wrote:

Hi there,

> I am trying to understand how nginx will receive desired domain request and
> how it will display the html pages.

<snip>

> Before moving to a real server I want to understand exactly how nginx gets
> request
> from desired domain name (example.com) and then shows the relevant data.

http://nginx.org/en/docs/http/request_processing.html

In short: the connection comes in on an ip:port, and includes an indication
of the server name requested (usually in the http request Host: header).

For every server{} defined, nginx checks for the ones with a "listen"
directive that is the best-match for the ip:port; for each of those
servers, nginx finds the one with the best-match "server_name" directive,
or else uses the default one.

After that, the server-level config or the best-match location{} is used
to decide how to respond to the request.

But all of that can only happen after the request gets to nginx.

> In browser when I type : test:80 , it shows webpage not available, instead
> of showing nginx default test page.

Browsers tend to hide the actual error message behind a "friendly" one.

What does

  curl -i http://test:80/

show?

I suspect it will be something along the lines of

  Couldn't resolve host 'test'

In that case, your browser never actually sent the request to nginx,
so nginx could do nothing about it.

One way to direct the request you want at the localhost web server is

  curl -i -H 'Host: test' http://localhost/

The best way is to set up name resolution such that your browser knows
that the name "test" corresponds to your nginx server. In the common case,
adding a line

  127.0.0.1  test

to /etc/hosts will make it all Just Work for all browsers on the system.

(If you're not in the common case, then other things may be needed. But
that's all outside of nginx.)

All the best,

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list