# Use different fastcgi backend in different folder

**URL:** <https://www.ruby-forum.com/t/use-different-fastcgi-backend-in-different-folder/147358>\
**Category:** NGINX\
**Created:** [September 1, 2008, 1:07am UTC](https://www.ruby-forum.com/t/use-different-fastcgi-backend-in-different-folder/147358 "2008-09-01T01:07:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samuel\_Vogel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@Samuel\_Vogel](https://www.ruby-forum.com/u/Samuel_Vogel)\
**Post date:** [September 1, 2008, 1:07am UTC](https://www.ruby-forum.com/t/use-different-fastcgi-backend-in-different-folder/147358/1 "2008-09-01T01:07:40Z")

</div>

I am wondering how I can tell nginx to use a different fastcgi backend  
for my phpmyadmin subfolder /pma.  
This is what I did:

```
    location ~ /pma/.+\.php$ {
            fastcgi_pass 127.0.0.1:9001;
    }

    location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
    }

```

The php backend on port 9001 is chrooted to the /pma folder. The problem  
is, that $fastcgi\_script\_name now contains the /pma, so the php backend  
can’t find the right file.  
How can I strip of the /pma from $fastcgi\_script\_name.

I don’t want to make another virtual host, since I don’t want a seperate  
port or subdomain just for phpmyadmin. Is a seperate vhost really the  
only way to go?

Regards,  
Samy

---

<div class="post-metadata">

**Author:** ![Samuel\_Vogel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@Samuel\_Vogel](https://www.ruby-forum.com/u/Samuel_Vogel)\
**Post date:** [September 1, 2008, 7:13am UTC](https://www.ruby-forum.com/t/use-different-fastcgi-backend-in-different-folder/147358/2 "2008-09-01T07:13:01Z")

</div>

On Mon, Sep 01, 2008 at 12:57:05AM +0200, Samuel Vogel wrote:

> ```
> }
> 
> ```
> 
> The php backend on port 9001 is chrooted to the /pma folder. The problem  
> is, that $fastcgi\_script\_name now contains the /pma, so the php backend  
> can’t find the right file.  
> How can I strip of the /pma from $fastcgi\_script\_name.
> 
> I don’t want to make another virtual host, since I don’t want a seperate  
> port or subdomain just for phpmyadmin. Is a seperate vhost really the  
> only way to go?

Try the following:

```
    location ~ /pma/.+\.php$ {
            rewrite ^/pma(/.+)$ $1 break;

            fastcgi_pass 127.0.0.1:9001;
    }

```

---

<div class="post-metadata">

**Author:** ![Samuel\_Vogel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@Samuel\_Vogel](https://www.ruby-forum.com/u/Samuel_Vogel)\
**Post date:** [September 1, 2008, 11:06am UTC](https://www.ruby-forum.com/t/use-different-fastcgi-backend-in-different-folder/147358/3 "2008-09-01T11:06:16Z")

</div>

This reminds me Igor, will it ever be possible (or is there some way  
it’s possible now) to use matched patterns in regex location blocks?

E.g.

location ~ ^(.\*)/blah$ {  
fastcgi\_param CUSTOM\_VAR $1;  
}

Cheers,  
Igor

---

<div class="post-metadata">

**Author:** ![Samuel\_Vogel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@Samuel\_Vogel](https://www.ruby-forum.com/u/Samuel_Vogel)\
**Post date:** [September 1, 2008, 3:06pm UTC](https://www.ruby-forum.com/t/use-different-fastcgi-backend-in-different-folder/147358/4 "2008-09-01T15:06:31Z")

</div>

Igor S. schrieb:

> Try the following:
> 
> ```
> location ~ /pma/.+\.php$ {
> rewrite ^/pma(/.+)$ $1 break;
> 
> fastcgi_pass 127.0.0.1:9001;
> }
> 
> ```

Thanks, this works!  
Even thou it works now, maybe somebody with some spare time could  
explain to me what this actually does.  
I couldn’t explain it to myself just with looking at the docs!

Thanks,  
Samy

---

<div class="post-metadata">

**Author:** ![Samuel\_Vogel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@Samuel\_Vogel](https://www.ruby-forum.com/u/Samuel_Vogel)\
**Post date:** [September 1, 2008, 3:18pm UTC](https://www.ruby-forum.com/t/use-different-fastcgi-backend-in-different-folder/147358/5 "2008-09-01T15:18:14Z")

</div>

On Mon, Sep 01, 2008 at 02:59:58PM +0200, Samuel Vogel wrote:

> explain to me what this actually does.  
> I couldn’t explain it to myself just with looking at the docs!

```
    rewrite ^/pma(/.+)$ $1 break;

```

deletes /pma/ from URI and disables (“break”) looking a new location  
for the new URI. Thus request uses this localtion configuration.

---

<div class="post-metadata">

**Author:** ![Samuel\_Vogel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@Samuel\_Vogel](https://www.ruby-forum.com/u/Samuel_Vogel)\
**Post date:** [September 1, 2008, 3:17pm UTC](https://www.ruby-forum.com/t/use-different-fastcgi-backend-in-different-folder/147358/6 "2008-09-01T15:17:39Z")

</div>

On Mon, Sep 01, 2008 at 09:57:47AM +0100, Igor C. wrote:

> This reminds me Igor, will it ever be possible (or is there some way  
> it’s possible now) to use matched patterns in regex location blocks?
> 
> E.g.
> 
> location ~ ^(.\*)/blah$ {  
> fastcgi\_param CUSTOM\_VAR $1;  
> }

I like to use location regex captures and it will be implemented.

---

<div class="post-metadata">

**Author:** ![Samuel\_Vogel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@Samuel\_Vogel](https://www.ruby-forum.com/u/Samuel_Vogel)\
**Post date:** [September 1, 2008, 5:10pm UTC](https://www.ruby-forum.com/t/use-different-fastcgi-backend-in-different-folder/147358/7 "2008-09-01T17:10:18Z")

</div>

I’m not sure how familiar you are with regex but just in case and if  
perhaps others are reading and it helps,

location ~ /pma/.+.php$

~ means use regex to match the location  
it starts by matching /pma/ and then .+ means one or more of any char  
$ means the pattern has to end with .php  
and the . just escapes the . so it isn’t any char like above  
this one has no brackets () so it doesn’t capture any data

next,

rewrite ^/pma(/.+)$ $1 break;

the ^ means matching from the start of line  
the brackets () mean capture what matches inside them  
in this case capture / and one ore more of any char  
since the capture ends up against the $ that means capture all til the  
end of line  
the $1 will contain whatever was captured in the part above  
and break means stop looking if this matches

rewrite means to match the first expression and rewrite as second  
expression  
so here since the second part is simply $1 it means whatever is captured  
by the brackets will be the entire result of the rewrite  
hence, here it is “/ plus anything after” but drops the part not in the  
capture

hope that helps… just looking to give back a wee little to the list.

Chris 🙂

---

<div class="post-metadata">

**Author:** ![Samuel\_Vogel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@Samuel\_Vogel](https://www.ruby-forum.com/u/Samuel_Vogel)\
**Post date:** [September 1, 2008, 5:23pm UTC](https://www.ruby-forum.com/t/use-different-fastcgi-backend-in-different-folder/147358/8 "2008-09-01T17:23:48Z")

</div>

Excellent, that will be a great addition.

Thanks,  
Igor

---

<div class="post-metadata">

**Author:** ![Samuel\_Vogel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@Samuel\_Vogel](https://www.ruby-forum.com/u/Samuel_Vogel)\
**Post date:** [September 1, 2008, 3:31pm UTC](https://www.ruby-forum.com/t/use-different-fastcgi-backend-in-different-folder/147358/9 "2008-09-01T15:31:10Z")

</div>

Igor S. schrieb:

> ```
> rewrite ^/pma(/.+)$ $1 break;
> 
> ```
> 
> deletes /pma/ from URI and disables (“break”) looking a new location  
> for the new URI. Thus request uses this localtion configuration  
> Okay, now I get it. Thanks!
