Nginx Server : Desired Domain Name on Local Host

Hi,

I’m on Fedora 16 with nginx installed using yum.

  1. /etc/nginx/conf.d contains : default.conf ssl.conf virtual.conf
  2. /etc/init.d/ contains : nginx (to start,stop etc
    server)
  3. /usr/share/nginx contains the default html files.
  4. /etc/nginx/nginx.conf contaings main config file which is calling
    default.conf

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

For that I edited /etc/nginx/conf.d/default.conf and wrote server_name
test;

and then I restarted nginx server.

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

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.

I have understood the concept of fetching files from proper folder as
per
the configuration file,
but not able to set desired domain name as a test on localhost.

May anyone let me know what would be the correct configuration ?


Thank You and Warm Regards,

Chetan Arvind Patil,
www.chetanpatil.info

Hi,

On Sat, Jun 16, 2012 at 7:19 PM, Francis D. [email protected]
wrote:

Couldn’t resolve host ‘test’

Yes.

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.

It worked. Thanks.

So, same configuration has to be done while moving to Linux hosted
server ?


Thank You and Warm Regards,

Chetan Arvind Patil,
www.chetanpatil.info

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.

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 D. [email protected]

On Sat, Jun 16, 2012 at 08:54:00PM +0530, Chetan Patil wrote:

On Sat, Jun 16, 2012 at 7:19 PM, Francis D. [email protected] wrote:

Hi there,

adding a line

127.0.0.1 test

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

It worked. Thanks.

So, same configuration has to be done while moving to Linux hosted server ?

Probably not. This is a client configuration, not an nginx one.

You will need that all clients (= browsers) know how to turn whatever
server name you want to use, into whatever IP address your server has.

Usually DNS takes care of this.

/etc/hosts is a useful temporary local setting until DNS records are
set up properly.

f

Francis D. [email protected]