Questions about Internal named location

I have a problem I can’t find an answer too and I’m wondering if I’m
doing the named internal location all wrong. Here is an example of my
config

location / {
try_files $uri $uri/ @www;
}

location @www {
include fastcgi_params;

fastcgi_index   index.php;
fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass    myphp;

}

When I go to /index.php I get the index.php recognized as a binary file
and the browser just wants to download the file. The file that is
downloaded is correct html so I know that the file hit myphp before it
was sent to my browser.

If I add this location:

location ~ .php$ {
fastcgi_pass myphp;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
}

index.php is displayed in the browser correctly so my question is why
does the @www location not correctly handle the php file?

This all started when I tried to setup one nginx server that has
multiple php sites under one url that needs a alias for the other sites.
Something like this:

root /var/www/somesite;

location / {
index.html index.php;
}
location /wordpress {
alias /var/www/wordpress;
try_files $uri $uri/ @wordpress;
}

Can anyone shed some light on how the try_files/named location works?
I’m using Nginx 0.8.36 btw

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,114926,114926#msg-114926

Hi,

On Jul 30, 2010, at 8:31 PM, heimdull wrote:

index.php is displayed in the browser correctly so my question is why
does the @www location not correctly handle the php file?

its because index.php is a real file. It never gets passed off to @www.
try_files is for testing real files on the filesystem. And returns that
url if it is successful. If it is unsuccesful it is passed off to @www.

alias /var/www/wordpress;
try_files $uri $uri/ @wordpress;
}

from the wiki http://wiki.nginx.org/Wordpress
might try this format
location /wordpress {
try_files $uri $uri/ /wordpress/index.php?q=$uri&args;
}

and then have your normal php location block for fastcgi settings.

On Fri, Jul 30, 2010 at 09:26:42PM +0200, Rob S. wrote:

alias /var/www/wordpress;
and then have your normal php location block for fastcgi settings.
It’s better to set a script name and a query string directly in
fastcgi_param to avoid surplus copy operations:

location /wordpress {
root /var/www;
try_files $uri $uri/ @wordpress;
}

location @wordpress {

fastcgi_param SCRIPT_FILENAME /var/www/wordpress/index.php;
fastcgi_param QUERY_STRING q=$uri&$args;
}


Igor S.
http://sysoev.ru/en/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs