# Create a virtual-host (server block)

**URL:** <https://www.ruby-forum.com/t/create-a-virtual-host-server-block/224364>\
**Category:** NGINX\
**Created:** [November 9, 2012, 12:19am UTC](https://www.ruby-forum.com/t/create-a-virtual-host-server-block/224364 "2012-11-09T00:19:55Z")\
**Posts on this page:** 3\
**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:** [November 9, 2012, 12:19am UTC](https://www.ruby-forum.com/t/create-a-virtual-host-server-block/224364/1 "2012-11-09T00:19:55Z")

</div>

hello

I try to put a virtual host (server block) on my website, i have some  
issue.

I have read the nginx tutorial for creat server block but after a lot of  
time i can’t get my server block and i dont understand why.  
Do you have something to configure on /etc/hosts or resolv.conf ?

this is my server block for my website.

_/vhosts-anable/test.conf_  
\*server {  
listen 80;  
server\_name [sd-32587.dedibox.fr](http://sd-32587.dedibox.fr);# localhost;

```
   # == Document ROOT
   root /home/sites_web/www.test.com/public;

   rails_env development;
   passenger_enabled on;

```

} \*

And this is my conf for the virtual-host.  
_/vhosts-anable/pipou.conf_  
\*server {

```
        listen 80 ;
        server_name websvn.sd-32587.dedibox.fr; #websvn.localhost

```

\*.localhost;

# rewrite ^/(.\*) [http://localhost/$1](http://localhost/$1) permanent;

# server\_name\_in\_redirect off;

# rewrite ^ [http://websvn.sd-32587.dedibox.fr$1](http://websvn.sd-32587.dedibox.fr$1) permanent;

```
        root /home/sites_web/websvn;
        index index.html;
        error_log /home/logs/websvn/error.log;
        access_log /home/logs/websvn/access.log;

```

}\*

when i m going to _[websvn.sd-32587.dedibox.fr](http://websvn.sd-32587.dedibox.fr)_ i have an error .  
Could you help me please  
thk a lot

---

<div class="post-metadata">

**Author:** ![grunk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/9dc877/32.png) [@grunk](https://www.ruby-forum.com/u/grunk)\
**Post date:** [November 9, 2012, 12:36am UTC](https://www.ruby-forum.com/t/create-a-virtual-host-server-block/224364/2 "2012-11-09T00:36:52Z")

</div>

On Fri, Nov 09, 2012 at 12:19:09AM +0100, Olivier M. wrote:

Hi there,

> I try to put a virtual host (server block) on my website, i have some issue.
> 
> I have read the nginx tutorial for creat server block but after a lot of  
> time i can’t get my server block and i dont understand why.

What do you do; what do you see; what do you expect to see?

Be specific.

> Do you have something to configure on /etc/hosts or resolv.conf ?

> **[How nginx processes a request](http://nginx.org/en/docs/http/request_processing.html)**

When your client makes a http request of nginx, nginx must decide which  
of your server{} blocks to use to process the request.

For your config, it looks like nginx does this purely based on the http  
Host: header.

> \*server {  
> listen 80;  
> server\_name [sd-32587.dedibox.fr](http://sd-32587.dedibox.fr);# localhost;

If you do

curl -H Host:sd-32587.dedibox.fr -i [http://your-server-name-or-ip/](http://your-server-name-or-ip/)

you should get content from here.

If [sd-32587.dedibox.fr](http://sd-32587.dedibox.fr) resolves to your server ip, then that is the same  
as

curl -i [http://sd-32587.dedibox.fr/](http://sd-32587.dedibox.fr/)

and the same as using any browser to fetch it.

> \*server {  
> listen 80 ;  
> server\_name [websvn.sd-32587.dedibox.fr](http://websvn.sd-32587.dedibox.fr); #websvn.localhost

Same thing here:

curl -H Host:websvn.sd-32587.dedibox.fr -i  
[http://your-server-name-or-ip/](http://your-server-name-or-ip/)

or

curl -i [http://websvn.sd-32587.dedibox.fr/](http://websvn.sd-32587.dedibox.fr/)

> when i m going to _[websvn.sd-32587.dedibox.fr](http://websvn.sd-32587.dedibox.fr)_ i have an error .

What error? I suggest using “curl” for testing, as above. It tends not  
to hide the real error from you.

My guess is “unable to resolve the hostname”.

> Could you help me please

If the problem is that your client can’t resolve the hostname, you must  
make your client be able to resolve the hostname.

Either put it in dns (so everyone who uses that dns service can see it);  
or put it in the local “hosts” file that your browser uses (so that only  
you can easily see it).

Good luck,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![grunk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/9dc877/32.png) [@grunk](https://www.ruby-forum.com/u/grunk)\
**Post date:** [November 9, 2012, 10:00am UTC](https://www.ruby-forum.com/t/create-a-virtual-host-server-block/224364/3 "2012-11-09T10:00:52Z")

</div>

* * *

nginx mailing list  
removed\_email\_address@domain.invalid  
[http://mailman.nginx.org/mailman/listinfo/nginx](http://mailman.nginx.org/mailman/listinfo/nginx)
