Possible bug in "root" declaration?


#1

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


#2

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.


#3

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


#4

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.