Having issues with nginx / root captures (0.7.53)

Igor Sysoev is at rambler-co.ru
Fri May 1 09:57:45 MSD 2009


On Thu, Apr 30, 2009 at 03:51:04PM -0700, Michael Shadle wrote:

> i have this, which seemed like it would work according to my attempt
> just a week ago...
> 
> server {
>         listen 80;
>         index index.php index.html;
>         server_name ~^foo(.*?)\.bar\.ssgisp\.com$;
>         root /home/mike/web/foo$1;
>         include /etc/nginx/defaults.conf;
>         include /etc/nginx/development.conf;
>         include /etc/nginx/expires.conf;
>         location ~ \.php$ {
>                 fastcgi_pass 127.0.0.1:11001;
>         }
> }
> 
> this is what the log shows in debug mode:
> 
> 2009/04/30 14:43:25 [debug] 8702#0: *16 http script copy: "/home/mike/web/foo"
> 2009/04/30 14:43:25 [debug] 8702#0: *16 http script capture: "html"
> 2009/04/30 14:43:25 [debug] 8702#0: *16 http filename:
> "/home/mike/web/foohtml/index.html"
> 2009/04/30 14:43:25 [debug] 8702#0: *16 add cleanup: 0000000015092358
> 2009/04/30 14:43:25 [error] 8702#0: *16 open()
> "/home/mike/web/foohtml/index.html" failed (13: Permission denied),
> client: 134.134.139.71, server: ~^foo(.*?)\.mike\.bar\.com$, request:
> "GET /index.html HTTP/1.1", host: "foo2.mike.bar.com"
> 
> non-debug:
> 
> 
> 2009/04/30 14:46:29 [crit] 8726#0: *17 stat()
> "/home/mike/web/foo/index.html" failed (13: Permission denied),
> client: 13.13.13.71, server: ~^foo(.*?)\.mike\.bar\.com$, request:
> "GET /index.html HTTP/1.1", host: "foo2.mike.bar.com"
> 2009/04/30 14:46:29 [error] 8726#0: *17 open()
> "/home/mike/web/foohtml/index.html" failed (13: Permission denied),
> client: 13.13.13.71, server: ~^foo(.*?)\.mike\.bar\.com$, request:
> "GET /index.html HTTP/1.1", host: "foo2.mike.bar.com"
> 
> All I want is
> 
> foo.mike.bar.com
> foo2.mike.bar.com
> foo-anything.mike.bar.com
> 
> to map to /home/mike/web/foo, /home/mike/web/foo2,
> /home/mike/web/foo-anything, etc...
> 
> Am I missing something here? and why is it capturing 'html' in the
> capture? I'm only creating a $1 from the server_name, is "html" a
> default somewhere?

First, "~^foo(.*?)\.bar\.ssgisp\.com$" will never match "foo2.mike.bar.com".
Second, "~^foo(.*?)\.bar\.com$" will capture "2.mike" with "foo2.mike.bar.com".

As to
 2009/04/30 14:43:25 [debug] 8702#0: *16 http script capture: "html"

Probably somewhere in

         include /etc/nginx/defaults.conf;
         include /etc/nginx/development.conf;
         include /etc/nginx/expires.conf;

this "html" is captured.

nginx configuration is declarative except ugly if/rewrite.
And these if/rewrite will run before the root variable substitution even
if root is described before if/rewrite:

         root /home/mike/web/foo$1;
         if (...)


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list