# Questions about Internal named location

**URL:** <https://www.ruby-forum.com/t/questions-about-internal-named-location/192470>\
**Category:** NGINX\
**Created:** [July 30, 2010, 8:32pm UTC](https://www.ruby-forum.com/t/questions-about-internal-named-location/192470 "2010-07-30T20:32:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![heimdull](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@heimdull](https://www.ruby-forum.com/u/heimdull)\
**Post date:** [July 30, 2010, 8:32pm UTC](https://www.ruby-forum.com/t/questions-about-internal-named-location/192470/1 "2010-07-30T20:32:07Z")

</div>

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:

> **[Questions about Internal named location](https://forum.nginx.org/read.php?2,114926,114926#msg-114926)**
>
> 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;

---

<div class="post-metadata">

**Author:** ![heimdull](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@heimdull](https://www.ruby-forum.com/u/heimdull)\
**Post date:** [July 30, 2010, 9:38pm UTC](https://www.ruby-forum.com/t/questions-about-internal-named-location/192470/2 "2010-07-30T21:38:16Z")

</div>

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 [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](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.

---

<div class="post-metadata">

**Author:** ![heimdull](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@heimdull](https://www.ruby-forum.com/u/heimdull)\
**Post date:** [July 30, 2010, 9:47pm UTC](https://www.ruby-forum.com/t/questions-about-internal-named-location/192470/3 "2010-07-30T21:47:38Z")

</div>

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.

> **[Igor Sysoev](http://sysoev.ru/en/)**
