# How to change the root for testing

**URL:** <https://www.ruby-forum.com/t/how-to-change-the-root-for-testing/221761>\
**Category:** NGINX\
**Created:** [July 29, 2012, 10:16am UTC](https://www.ruby-forum.com/t/how-to-change-the-root-for-testing/221761 "2012-07-29T10:16:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [July 29, 2012, 10:16am UTC](https://www.ruby-forum.com/t/how-to-change-the-root-for-testing/221761/1 "2012-07-29T10:16:06Z")

</div>

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. ☹

```
 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).

---

<div class="post-metadata">

**Author:** ![dcian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dcian](https://www.ruby-forum.com/u/dcian)\
**Post date:** [July 30, 2012, 5:19pm UTC](https://www.ruby-forum.com/t/how-to-change-the-root-for-testing/221761/2 "2012-07-30T17:19:51Z")

</div>

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:

> **[Re: How to change the root for testing](https://forum.nginx.org/read.php?2,229067,229097#msg-229097)**
>
> 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. :( index index.php index.html index.htm; roo

---

<div class="post-metadata">

**Author:** ![dcian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dcian](https://www.ruby-forum.com/u/dcian)\
**Post date:** [August 1, 2012, 12:31pm UTC](https://www.ruby-forum.com/t/how-to-change-the-root-for-testing/221761/3 "2012-08-01T12:31:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dcian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dcian](https://www.ruby-forum.com/u/dcian)\
**Post date:** [August 1, 2012, 8:46pm UTC](https://www.ruby-forum.com/t/how-to-change-the-root-for-testing/221761/4 "2012-08-01T20:46:01Z")

</div>

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](http://nginx.org/r/location)), 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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
