# Possible bug in "root" declaration?

**URL:** <https://www.ruby-forum.com/t/possible-bug-in-root-declaration/169031>\
**Category:** NGINX\
**Created:** [May 28, 2009, 4:12pm UTC](https://www.ruby-forum.com/t/possible-bug-in-root-declaration/169031 "2009-05-28T16:12:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Systems\_Maintenance](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e36b37/32.png) [@Systems\_Maintenance](https://www.ruby-forum.com/u/Systems_Maintenance)\
**Post date:** [May 28, 2009, 4:12pm UTC](https://www.ruby-forum.com/t/possible-bug-in-root-declaration/169031/1 "2009-05-28T16:12:08Z")

</div>

Below is part of a server block for a particular vhost:

server {  
server\_name mysite.tld ~^.+.mysite.tld$;

```
set $base /var/www/mysite;

if ( $host ~* "^(x|y|z)\.mysite\.tld$" ){
   set $files misc;
}

if ( $host ~* "^(admin)\.mysite\.tld$" ){
   set $files admin;
}

if ( $host = "mysite.tld" ){
   set $files home;
}

root $base/$files/www;
error_page 404 $base/errors/404.html;

location / {
   try_files $uri @webapp;
}

location @webapp {
   rewrite ^/([\w\d]+)/([\w\d]+)(.*)? /index.php/$1/$2?_params=$3 

```

last;  
}

```
location ~ \.php($|/) {
    set $script $uri;
    set $path_info "";

    if ($uri ~ "^(.+\.php)(/.+)") {
        set $script $1;
        set $path_info $2;
    }

    fastcgi_pass unix:/tmp/php-socket;
    include conf/fastcgi_params;
    fastcgi_intercept_errors on;
    fastcgi_param SCRIPT_FILENAME $base/$interface$script;
    fastcgi_param PATH_INFO $path_info;
    fastcgi_index index.php;
}

```

}

What I’m seeing in my error log is that the error\_page its trying to  
return is: /var/www/mysite/var/www/mysite/errors/404.html instead of the  
expected /var/www/mysite/errors/404.html

I’ve also tried (with no success):

error\_page 404 @notfound;  
location @notfound {  
root $base/errors;  
error\_page 404 404.html;  
index 404.html;  
}

Here’s my version information, if it helps:

# nginx -V

nginx version: nginx/0.7.55  
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-44)  
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx  
–conf-path=/etc/nginx/nginx.conf  
–error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid  
–with-rtsig\_module --with-select\_module --with-poll\_module  
–with-http\_ssl\_module --with-http\_stub\_status\_module  
–with-http\_gzip\_static\_module --with-http\_flv\_module  
–with-http\_random\_index\_module  
–http-log-path=/var/log/nginx/access.log --with-md5=/usr/lib  
–with-sha1=/usr/lib --without-mail\_pop3\_module  
–without-mail\_imap\_module --without-mail\_smtp\_module  
–add-module=nginx\_circle\_gif-0.1.3

---

<div class="post-metadata">

**Author:** ![Systems\_Maintenance](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e36b37/32.png) [@Systems\_Maintenance](https://www.ruby-forum.com/u/Systems_Maintenance)\
**Post date:** [May 28, 2009, 4:28pm UTC](https://www.ruby-forum.com/t/possible-bug-in-root-declaration/169031/2 "2009-05-28T16:28:41Z")

</div>

On Thu, May 28, 2009 at 02:51:11PM +0100, Systems Maintenance wrote:

> if ( $host ~\* “^(admin).mysite.tld$” ){  
> set $files admin;  
> }
> 
> if ( $host = “mysite.tld” ){  
> set $files home;  
> }

This is not effective way. It’s better to use map:

map $host $files {  
default home;  
mysite.tld home;  
admin.mysite.tld admin;  
x.mysite.tld misc;  
y.mysite.tld misc;  
z.mysite.tld misc;  
}

> ```
> include conf/fastcgi_params;
> 
> ```
> 
> expected /var/www/mysite/errors/404.html  
> error\_page uses URI, but not file:

```
error_page 404 /errors/404.html;

location = /error/404.html {
    set /var/www/mysite;
}

```

> I’ve also tried (with no success):
> 
> error\_page 404 @notfound;  
> location @notfound {  
> root $base/errors;  
> error\_page 404 404.html;  
> index 404.html;  
> }

This is not valid way.

> –with-http\_gzip\_static\_module --with-http\_flv\_module  
> –with-http\_random\_index\_module  
> –http-log-path=/var/log/nginx/access.log  
> –with-md5=/usr/lib --with-sha1=/usr/lib

–with-md5- and --with-sha1= are required to build theses libraries  
from sources.

> –without-mail\_pop3\_module  
> –without-mail\_imap\_module --without-mail\_smtp\_module

mail modules are not built by default.

---

<div class="post-metadata">

**Author:** ![Systems\_Maintenance](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e36b37/32.png) [@Systems\_Maintenance](https://www.ruby-forum.com/u/Systems_Maintenance)\
**Post date:** [May 28, 2009, 4:51pm UTC](https://www.ruby-forum.com/t/possible-bug-in-root-declaration/169031/3 "2009-05-28T16:51:34Z")

</div>

Igor S. wrote:

> > ```
> > set $files misc;
> > 
> > ```

We’re also capturing “wildcard” subdomains in the vhost with:

if ( $host ~\* “^([a-zA-Z]+[a-zA-Z0-9]\*).mysite.tld$” ){  
set $files custom;  
}

so if someone hits “a8df15f.mysite.tld” they get a custom homepage, but  
“18sdf351f.mysite.tld” is invalid and therefore they get the “home  
page”. Can this also be reproduced with the “map” directive?

> > ```
> > include conf/fastcgi_params;
> > 
> > ```
> > 
> > expected /var/www/mysite/errors/404.html
> 
> error\_page uses URI, but not file:
> 
> ```
> error_page 404 /errors/404.html;
> 
> location = /error/404.html {
> set /var/www/mysite;
> }
> 
> ```

Thanks, I’ll try this.

> > –without-mail\_pop3\_module  
> > –without-mail\_imap\_module --without-mail\_smtp\_module  
> > mail modules are not built by default.

This isn’t mentioned in “./configure --help”:

–with-mail enable POP3/IMAP4/SMTP proxy module  
–with-mail\_ssl\_module enable ngx\_mail\_ssl\_module  
–without-mail\_pop3\_module disable ngx\_mail\_pop3\_module  
–without-mail\_imap\_module disable ngx\_mail\_imap\_module  
–without-mail\_smtp\_module disable ngx\_mail\_smtp\_module

---

<div class="post-metadata">

**Author:** ![Systems\_Maintenance](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e36b37/32.png) [@Systems\_Maintenance](https://www.ruby-forum.com/u/Systems_Maintenance)\
**Post date:** [May 28, 2009, 5:04pm UTC](https://www.ruby-forum.com/t/possible-bug-in-root-declaration/169031/4 "2009-05-28T17:04:32Z")

</div>

On Thu, May 28, 2009 at 03:42:19PM +0100, Systems Maintenance wrote:

> > > if ( $host ~\* “^(x|y|z).mysite.tld$” ){
> > 
> > }
> 
> We’re also capturing “wildcard” subdomains in the vhost with:
> 
> if ( $host ~\* “^([a-zA-Z]+[a-zA-Z0-9]\*).mysite.tld$” ){  
> set $files custom;  
> }
> 
> so if someone hits “a8df15f.mysite.tld” they get a custom homepage, but  
> “18sdf351f.mysite.tld” is invalid and therefore they get the “home  
> page”. Can this also be reproduced with the “map” directive?

No, only “\*.mysite.tld”.

> > > ```
> > > include conf/fastcgi_params;
> > > 
> > > ```
> > > 
> > > expected /var/www/mysite/errors/404.html  
> > > Thanks, I’ll try this.  
> > > –without-mail\_smtp\_module disable ngx\_mail\_smtp\_module  
> > > If there is --with-mail and there is no --without-mail, then this should  
> > > mean that mail modules are not built by default.
