Override index.php for a subdirectory

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 - [email protected]

YetOpen S.r.l. - http://www.yetopen.it/

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

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

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. [email protected]

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 - [email protected]

YetOpen S.r.l. - http://www.yetopen.it/