# Problem with setting Virtual Hosts

**URL:** <https://www.ruby-forum.com/t/problem-with-setting-virtual-hosts/204869>\
**Category:** NGINX\
**Created:** [March 23, 2011, 6:16pm UTC](https://www.ruby-forum.com/t/problem-with-setting-virtual-hosts/204869 "2011-03-23T18:16:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 23, 2011, 6:16pm UTC](https://www.ruby-forum.com/t/problem-with-setting-virtual-hosts/204869/1 "2011-03-23T18:16:46Z")

</div>

i need help ☹

I wrote as the following site.

[http://wiki.nginx.org/VirtualHostExample](http://wiki.nginx.org/VirtualHostExample)

here is my nginx.conf

user www www;  
worker\_processes 1;  
error\_log /data/logs/nginx\_error.log crit;  
pid /opt/webserver/nginx/nginx.pid;  
#Specifies the value for maximum file descriptors that can be opened by  
this process.  
worker\_rlimit\_nofile 65535;  
events  
{  
use epoll;  
worker\_connections 65535;  
}  
http  
{  
include mime.types;  
default\_type application/octet-stream;

#charset gb2312;

server\_names\_hash\_bucket\_size 128;  
client\_header\_buffer\_size 32k;  
large\_client\_header\_buffers 4 32k;  
client\_max\_body\_size 8m;

sendfile on;  
tcp\_nopush on;

keepalive\_timeout 60;

tcp\_nodelay on;

fastcgi\_connect\_timeout 300;  
fastcgi\_send\_timeout 300;  
fastcgi\_read\_timeout 300;  
fastcgi\_buffer\_size 64k;  
fastcgi\_buffers 4 64k;  
fastcgi\_busy\_buffers\_size 128k;  
fastcgi\_temp\_file\_write\_size 128k;

gzip on;  
gzip\_min\_length 1k;  
gzip\_buffers 4 16k;  
gzip\_http\_version 1.0;  
gzip\_comp\_level 2;  
gzip\_types text/plain application/x-javascript text/css  
application/xml;  
gzip\_vary on;  
server {  
listen 80 default;  
server\_name \_;  
access\_log logs/default.access.log;

```
server_name_in_redirect off;

root /data/www;

```

}  
#limit\_zone crawler $binary\_remote\_addr 10m;  
server {

# Replace this port with the right one for your requirements

listen 80; #could also be 1.2.3.4:80

# Multiple hostnames separated by spaces. Replace these as well.

server\_name [star.domain.com](http://star.domain.com) \*.domain.com; # Alternately: \_

root /data/www/$host/;

error\_page 404 errors/404.html;  
access\_log logs/star.domain.com.access.log;

index index.php index.html index.htm;

# serve static files directly

location ~\* .(jpg|jpeg|gif|css|png|js|ico|html)$ {  
access\_log off;  
expires max;  
}

location ~ .php$ {  
fastcgi\_intercept\_errors on;  
# By all means use a different server for the fcgi processes if you  
need to  
fastcgi\_pass 127.0.0.1:9000;  
}

location ~ /.ht {  
deny all;  
}  
}

}

when i vist [a.domain.com](http://a.domain.com)

but the website redirect to the following site.

[http://a.domaincom/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/404.html](http://a.domaincom/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/404.html)

Posted at Nginx Forum:

> **[problem with setting Virtual Hosts](https://forum.nginx.org/read.php?2,185203,185203#msg-185203)**
>
> i need help :( I wrote as the following site. http://wiki.nginx.org/VirtualHostExample here is my nginx.conf user www www; worker\_processes 1; error\_log /data/logs/nginx\_error.log crit; pid

---

<div class="post-metadata">

**Author:** ![chatfeed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b782af/32.png) [@chatfeed](https://www.ruby-forum.com/u/chatfeed)\
**Post date:** [March 23, 2011, 7:08pm UTC](https://www.ruby-forum.com/t/problem-with-setting-virtual-hosts/204869/2 "2011-03-23T19:08:43Z")

</div>

On Wed, Mar 23, 2011 at 01:16:14PM -0400, chatfeed wrote:

Hi there,

> I wrote as the following site.
> 
> [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/VirtualHostExample)

Despite what it shows on that page, it is usually best…

> server\_name [star.domain.com](http://star.domain.com) \*.domain.com; # Alternately: \_
> 
> root /data/www/$host/;
> 
> error\_page 404 errors/404.html;

…if the last argument to error\_page starts with “/” or “@”.

So make it “/errors/404.html” and you should see something more  
useful. (Or just remove the line entirely, for a slightly different  
result.)

> when i vist [a.domain.com](http://a.domain.com)
> 
> but the website redirect to the following site.

[http://a.domaincom/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/404.html](http://a.domaincom/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/errors/404.html)

You ask for [http://a.domain.com/](http://a.domain.com/); nginx presumably doesn’t see the file  
/data/www/a.domain.com/index.php and so generates a http 404 error; your  
error\_page setting says “do an external redirect to errors/404.html”,  
which is returned to your browser.

It then asks for [http://a.domain.com/errors/404.html](http://a.domain.com/errors/404.html); nginx doesn’t see  
the file /data/www/a.domain.com/errors/404.html and generates a http  
404 error which becomes an external redirect, so your browser asks for  
[http://a.domain.com/errors/errors/404.html](http://a.domain.com/errors/errors/404.html); and this continues until  
your browser decides it has seen too many redirects.

So: delete or change the error\_page line to prevent the loop; and add  
content to the right directory to avoid the initial 404 error.

Good luck with it,

## f

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