Quantcast

server_name capture and $document_root

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

server_name capture and $document_root

Rapsey
I'm trying to use the new feature from 0.7.40 - captures in server_name.
I use $document_root in SCRIPT_FILENAME for fastcgi. The problem is that the captured part of server_name is not being used. If I check my access log, it will say this:
404 .... /var/www/htdocs//index.php

For a regular index.php, the path will be correct and the captured part will be in it:
200 .... /var/www/htdocs/domain/index.html

This is the gist of my config:

server {
  listen 80;
  server_name   ~^(www\.)?(.+)\.(.+)$;
  root /var/www/htdocs/$2;

  log_format  main  '$status "$request" $body_bytes_sent $remote_addr $document_root$fastcgi_script_name';
  ....

   location ~ .php$ { 
      fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
      ... # normal fastcgi params
    }
  }
}

Is this a bug or an incorrect config on my part?


thank you,
Sergej

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: server_name capture and $document_root

Igor Sysoev
On Mon, Mar 16, 2009 at 02:35:06PM +0100, Rapsey wrote:

> I'm trying to use the new feature from 0.7.40 - captures in server_name.
> I use $document_root in SCRIPT_FILENAME for fastcgi. The problem is that the
> captured part of server_name is not being used. If I check my access log, it
> will say this:
> 404 .... /var/www/htdocs//index.php
>
> For a regular index.php, the path will be correct and the captured part will
> be in it:
> 200 .... /var/www/htdocs/domain/index.html
>
> This is the gist of my config:
>
> server {
>   listen 80;
>   server_name   ~^(www\.)?(.+)\.(.+)$;
>   root /var/www/htdocs/$2;
>
>   log_format  main  '$status "$request" $body_bytes_sent $remote_addr
> $document_root$fastcgi_script_name';
>   ....
>
>    location ~ .php$ {
>       fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
>       ... # normal fastcgi params
>     }
>   }
> }
>
> Is this a bug or an incorrect config on my part?

The "root /var/www/htdocs/$2" is evaluated in "location ~ .php$" context,
therefore, the ".php$" regex clears $2. The woraround is:

server {

   server_name    ~^(www\.)?(.+)\.(.+)$;
   set   $domain  $2;
   root /var/www/htdocs/$domain;

BTW, you better to use 0.7.42, as there are bugfixes in captures.


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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: server_name capture and $document_root

Rapsey
Works perfectly. Thank you.


Sergej


2009/3/16 Igor Sysoev <[hidden email]>
On Mon, Mar 16, 2009 at 02:35:06PM +0100, Rapsey wrote:

> I'm trying to use the new feature from 0.7.40 - captures in server_name.
> I use $document_root in SCRIPT_FILENAME for fastcgi. The problem is that the
> captured part of server_name is not being used. If I check my access log, it
> will say this:
> 404 .... /var/www/htdocs//index.php
>
> For a regular index.php, the path will be correct and the captured part will
> be in it:
> 200 .... /var/www/htdocs/domain/index.html
>
> This is the gist of my config:
>
> server {
>   listen 80;
>   server_name   ~^(www\.)?(.+)\.(.+)$;
>   root /var/www/htdocs/$2;
>
>   log_format  main  '$status "$request" $body_bytes_sent $remote_addr
> $document_root$fastcgi_script_name';
>   ....
>
>    location ~ .php$ {
>       fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
>       ... # normal fastcgi params
>     }
>   }
> }
>
> Is this a bug or an incorrect config on my part?

The "root /var/www/htdocs/$2" is evaluated in "location ~ .php$" context,
therefore, the ".php$" regex clears $2. The woraround is:

server {

  server_name    ~^(www\.)?(.+)\.(.+)$;
  set   $domain  $2;
  root /var/www/htdocs/$domain;

BTW, you better to use 0.7.42, as there are bugfixes in captures.


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


Loading...