Forum: NGINX try_files in subdirectory

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mathew D. (Guest)
on 2009-05-18 02:20
(Received via mailing list)
Hi,
I am using try_files in a subdirectory and I'm coming up with some
issues.

# default

server

{

server_name localhost;

 location ~ \.php$

{

try_files $uri $uri/;

fastcgi_pass 127.0.0.1:9000;

include fastcgi_params;

}

 location /devkit/

{

try_files $uri $uri/ @kohana;

}


> location @kohana

{

fastcgi_pass 127.0.0.1:9000;

include fastcgi_params;

fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/devkit/index.php;

}

}


This URL works correctly,

http://www.domain.com/devkit/index.php/coaster/17/...


but when I remove the index.php file I get :

The page you requested devkit/coaster/17/olympia-looping could not be
found.

but it should be coaster/17/olympia-looping instead.

Any ideas?
Michael S. (Guest)
on 2009-05-18 02:54
(Received via mailing list)
It's probably matching the .php first. Put that in a location / block
so devkit can be found first.

On May 17, 2009, at 3:05 PM, Mathew D.
<removed_email_address@domain.invalid
Mathew D. (Guest)
on 2009-05-20 02:48
(Received via mailing list)
That had no effect, any other ideas?

2009/5/17 Michael S. <removed_email_address@domain.invalid>
Igor S. (Guest)
on 2009-05-20 13:26
(Received via mailing list)
On Sun, May 17, 2009 at 11:05:23PM +0100, Mathew D. wrote:

>
>  location ~ \.php$
>
> {
>
> try_files $uri $uri/;

Here "$uri/" is fallback parameter. However, this is not cause of the
problem.

> try_files $uri $uri/ @kohana;
> include fastcgi_params;
> http://www.domain.com/devkit/index.php/coaster/17/...
>
>
> but when I remove the index.php file I get :
>
> The page you requested devkit/coaster/17/olympia-looping could not be found.
>
> but it should be coaster/17/olympia-looping instead.

You need something like this:

location /devkit {
    try_files $uri $uri/ @kohana;
}

location @kohana {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_split_path_info         ^(/devkit)(/.*)$;
    fastcgi_param  SCRIPT_FILENAME
/usr/local/nginx/html/devkit/index.php;
    fastcgi_param  PATH_INFO        $fastcgi_path_info;
}
This topic is locked and can not be replied to.