How to change the root for testing

Hi all,

I want to change the root for location /testing.
How can I do this?

This is what I have in the middle of this server stanza, yet the testing
reseller is served from the live root. :frowning:

 index index.php index.html index.htm;
 root /home/ian/websites/coachmaster/htsecure;
 # move root for testing reseller
 location /testing {
    root /home/ian/websites/coachmaster/testing;
 }
 # take resellers off the front of path to rs=reseller param
 rewrite ^/(kaleidoscope|chat|Spanish|3MCoach|testing)(.*)$ $2?rs=$1

last;
# php to fastcgi
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
fastcgi_param HTTPS ON;
include /etc/nginx/fastcgi_params;
}

I was actually hoping to switch the root on a per-reseller basis,
perhaps by testing for a file I can “touch” or delete to switch to the
new configuration, but I can’t think how to do that.

Thanks
Ian

(Sorry if this is a duplicate - the first did not appear).

Do you mean that requesting /testing/something.php tries to use
/home/ian/websites/coachmaster/htsecure/something.php instead of
/home/ian/websites/coachmaster/testing/something.php?

In the regexp location the document_root is inherited from the server
context.

I think this would help you:

map $reseller $reseller_path {
default /home/ian/websites/coachmaster/htsecure;
testing /home/ian/websites/coachmaster/testing;
}

server {
index index.php index.html index.htm;
root /home/ian/websites/coachmaster/htsecure;

rewrite ^/(?kaleidoscope|chat|Spanish|3MCoach|testing)(.*)$
$2?rs=$reseller last;

location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $reseller_path$fastcgi_script_name;
fastcgi_param HTTPS ON;
include /etc/nginx/fastcgi_params;
}
}

Posted at Nginx Forum:

Hi leki75,

Comments interspersed.

On 30/07/2012 16:19, leki75 wrote:

Do you mean that requesting /testing/something.php tries to use
/home/ian/websites/coachmaster/htsecure/something.php instead of
/home/ian/websites/coachmaster/testing/something.php?
Yes, Exactly.

In the regexp location the document_root is inherited from the server
context.
I expected that to be replaced as the location is more specific. Oh
well.
root /home/ian/websites/coachmaster/htsecure;

rewrite ^/(?kaleidoscope|chat|Spanish|3MCoach|testing)(.*)$
$2?rs=$reseller last;
I don’t understand what the ? bit is doing. (and Google has
been no help!).

Regards
Ian

location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $reseller_path$fastcgi_script_name;
fastcgi_param HTTPS ON;
include /etc/nginx/fastcgi_params;
}
}

–
Ian H.
31 Sheerwater, Northampton NN3 5HU,
Tel: 01604 513875
Preparing eBooks for Kindle and ePub formats to give the best reader
experience.

On Wed, Aug 01, 2012 at 11:30:08AM +0100, Ian H. wrote:

On 30/07/2012 16:19, leki75 wrote:

Hi there,

Do you mean that requesting /testing/something.php tries to use
/home/ian/websites/coachmaster/htsecure/something.php instead of
/home/ian/websites/coachmaster/testing/something.php?
Yes, Exactly.

In the regexp location the document_root is inherited from the server
context.
I expected that to be replaced as the location is more specific. Oh well.

One request is handled by one location.

You have the location definitions:

location /testing {}
location ~ .php$ {}

Per the docs (Module ngx_http_core_module), the request for
/testing/something.php is handled by the second location there.

What you want is some way of setting “fastcgi_param SCRIPT_FILENAME”
to point to the testing filename, when appropriate.

Probably the least-impact way of doing this would be to add a new

location ~ ^/testing/.*php$ {}

with the same content as your current php location, plus the root
directive that you want. There are other ways of doing this too.

rewrite ^/(?kaleidoscope|chat|Spanish|3MCoach|testing)(.*)$
$2?rs=$reseller last;
I don’t understand what the ? bit is doing. (and Google has
been no help!).

It’s a perl-compatible regex named capture. Older pcre libraries may
not recognise the syntax, in which case you should see a clear warning
to that effect.

All the best,

f

Francis D. [email protected]