# Nginx Server : Desired Domain Name on Local Host

**URL:** <https://www.ruby-forum.com/t/nginx-server-desired-domain-name-on-local-host/220681>\
**Category:** NGINX\
**Created:** [June 16, 2012, 3:10pm UTC](https://www.ruby-forum.com/t/nginx-server-desired-domain-name-on-local-host/220681 "2012-06-16T15:10:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [June 16, 2012, 3:10pm UTC](https://www.ruby-forum.com/t/nginx-server-desired-domain-name-on-local-host/220681/1 "2012-06-16T15:10:01Z")

</div>

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](http://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

---

<div class="post-metadata">

**Author:** ![Chetan\_Patil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/96bed5/32.png) [@Chetan\_Patil](https://www.ruby-forum.com/u/Chetan_Patil)\
**Post date:** [June 16, 2012, 5:24pm UTC](https://www.ruby-forum.com/t/nginx-server-desired-domain-name-on-local-host/220681/2 "2012-06-16T17:24:59Z")

</div>

Hi,

On Sat, Jun 16, 2012 at 7:19 PM, Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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

---

<div class="post-metadata">

**Author:** ![Chetan\_Patil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/96bed5/32.png) [@Chetan\_Patil](https://www.ruby-forum.com/u/Chetan_Patil)\
**Post date:** [June 16, 2012, 3:50pm UTC](https://www.ruby-forum.com/t/nginx-server-desired-domain-name-on-local-host/220681/3 "2012-06-16T15:50:20Z")

</div>

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](http://example.com)) and then shows the relevant data.

> **[How nginx processes a request](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/](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/](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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Chetan\_Patil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/96bed5/32.png) [@Chetan\_Patil](https://www.ruby-forum.com/u/Chetan_Patil)\
**Post date:** [June 16, 2012, 7:32pm UTC](https://www.ruby-forum.com/t/nginx-server-desired-domain-name-on-local-host/220681/4 "2012-06-16T19:32:21Z")

</div>

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

> On Sat, Jun 16, 2012 at 7:19 PM, Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
