# Override index.php for a subdirectory

**URL:** <https://www.ruby-forum.com/t/override-index-php-for-a-subdirectory/238101>\
**Category:** NGINX\
**Created:** [December 17, 2013, 12:27pm UTC](https://www.ruby-forum.com/t/override-index-php-for-a-subdirectory/238101 "2013-12-17T12:27:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [December 17, 2013, 12:27pm UTC](https://www.ruby-forum.com/t/override-index-php-for-a-subdirectory/238101/1 "2013-12-17T12:27:05Z")

</div>

Hi.  
I need to override default index file for a subdirectory only.

My actual config (pretty much ubuntu’s default):  
server {  
listen 80 default\_server;  
root /var/www;  
index index.php index.html index.htm;  
server\_name localhost;  
location / {  
try\_files $uri $uri/ /index.html;  
}  
location ~ .php$ {  
fastcgi\_split\_path\_info ^(.+.php)(/.+)$;  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_index index.php;  
include fastcgi\_params;  
}  
location ~ /.ht {  
deny all;  
}  
}

Then in a second file I added:  
server {  
location ~ /work/management\_site/ {  
fastcgi\_index index-maxxer.php;  
index index-maxxer.php;  
try\_files $uri index-maxxer.php?$args;

```
    set $fsn "/index-maxxer.php";
    fastcgi_param SCRIPT_FILENAME $document_root$fsn;
}

```

}

But doesn’t work.  
How can I accomplish that?

thanks

–  
Lorenzo Milesi - removed\_email\_address@domain.invalid

YetOpen S.r.l. - [http://www.yetopen.it/](http://www.yetopen.it/)

---

<div class="post-metadata">

**Author:** ![Lorenzo\_Milesi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/4bbf92/32.png) [@Lorenzo\_Milesi](https://www.ruby-forum.com/u/Lorenzo_Milesi)\
**Post date:** [December 17, 2013, 9:49pm UTC](https://www.ruby-forum.com/t/override-index-php-for-a-subdirectory/238101/2 "2013-12-17T21:49:12Z")

</div>

On Tue, Dec 17, 2013 at 12:26:16PM +0100, Lorenzo Milesi wrote:

Hi there,

> I need to override default index file for a subdirectory only.

[http://nginx.org/r/location](http://nginx.org/r/location)

Make sure that requests for this subdirectory only are handled in a  
specific location block.

Set the default index file within that location block.

\> server { \> listen 80 default\_server; \> server\_name localhost; \> location / { \> location ~ \.php$ { \> location ~ /\.ht { \> } \> server { \> location ~ /work/management\_site/ { \> }

> But doesn’t work.  
> How can I accomplish that?

[http://nginx.org/en/docs/http/request\_processing.html](http://nginx.org/en/docs/http/request_processing.html)

When a request comes in, first the one server{} to handle it is chosen.

Then the one location{} to handle it within that server{} is chosen.

You will probably want your new location, which will probably use “^~”,  
to be in the same server{} block as the rest of your configuration.

## f

Francis D. removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Lorenzo\_Milesi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/4bbf92/32.png) [@Lorenzo\_Milesi](https://www.ruby-forum.com/u/Lorenzo_Milesi)\
**Post date:** [December 18, 2013, 4:06pm UTC](https://www.ruby-forum.com/t/override-index-php-for-a-subdirectory/238101/3 "2013-12-18T16:06:09Z")

</div>

> You will probably want your new location, which will probably use “^~”,  
> to be in the same server{} block as the rest of your configuration.

Thanks for your suggestion.

For benefit of others I solved this way:

server {  
[…]

```
location /work/management_site/ {
    location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
        try_files $uri =404;
    }
    set $yii_bootstrap "index-maxxer.php";
    index index-maxxer.php;
    try_files $uri $uri/ 

```

/work/management\_site/index-maxxer.php?$args;  
set $fsn /$yii\_bootstrap;  
if (-f $document\_root$fastcgi\_script\_name){  
set $fsn $fastcgi\_script\_name;  
}

```
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index-maxxer.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fsn;
}

```

}

It can probably be improved, but right now it works!

## Thanks again

Lorenzo Milesi - removed\_email\_address@domain.invalid

YetOpen S.r.l. - [http://www.yetopen.it/](http://www.yetopen.it/)
