# Location not called properly

**URL:** <https://www.ruby-forum.com/t/location-not-called-properly/213098>\
**Category:** NGINX\
**Created:** [October 23, 2011, 10:14pm UTC](https://www.ruby-forum.com/t/location-not-called-properly/213098 "2011-10-23T22:14:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [October 23, 2011, 10:14pm UTC](https://www.ruby-forum.com/t/location-not-called-properly/213098/1 "2011-10-23T22:14:12Z")

</div>

Hi all,

I’m trying to call a location of this format:

location = /somedir/file1.php {  
try\_files @cache =404;  
}

location = /anotherdir/file2.php {  
try\_files @cache =404;  
}

location @cache {  
try\_files $uri =404;  
fastcgi\_split\_path\_info ^(.+.php)(/.+)$;  
fastcgi\_pass fastcgi;  
fastcgi\_param PATH\_INFO $fastcgi\_path\_info;  
fastcgi\_param PATH\_TRANSLATED  
$document\_root$fastcgi\_script\_name;  
include fastcgi.conf;  
}

For some reason is not working, can you please let me know what is the  
proper syntax?

Posted at Nginx Forum:

> **[Location not called properly](https://forum.nginx.org/read.php?2,217122,217122#msg-217122)**
>
> Hi all, I'm trying to call a location of this format: location = /somedir/file1.php { try\_files @cache =404; } location = /anotherdir/file2.php { try\_files @cache =404; } location @cache { try\_fil

---

<div class="post-metadata">

**Author:** ![teck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b2d939/32.png) [@teck](https://www.ruby-forum.com/u/teck)\
**Post date:** [October 24, 2011, 1:33am UTC](https://www.ruby-forum.com/t/location-not-called-properly/213098/2 "2011-10-24T01:33:17Z")

</div>

On Sun, Oct 23, 2011 at 04:13:37PM -0400, TECK wrote:

Hi there,

> I’m trying to call a location of this format:
> 
> location = /somedir/file1.php {  
> try\_files @cache =404;  
> }

Only the last parameter of try\_files is “magic”. Any others that start  
with @ or = will probably not do what you want.

> For some reason is not working, can you please let me know what is the  
> proper syntax?

It’s not immediately clear what it is that you want, that is different  
from “include fastcgi.conf” at server level and “fastcgi\_pass fastcgi”  
in your exact-match locations.

If that isn’t adequate, can you describe more?

Good luck,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![teck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b2d939/32.png) [@teck](https://www.ruby-forum.com/u/teck)\
**Post date:** [October 24, 2011, 1:03pm UTC](https://www.ruby-forum.com/t/location-not-called-properly/213098/3 "2011-10-24T13:03:11Z")

</div>

The fastcgi value is the name of my upstream.  
The idea is: once the location /somedir/file1.php is reached,  
everything in @cache should execute.  
In this way, I don’t repeat several times the same code. This works:

location /somedir/file1.php {  
try\_files $uri =404;  
fastcgi\_split\_path\_info ^(.+.php)(/.+)$;  
fastcgi\_pass fastcgi;  
fastcgi\_param PATH\_INFO $fastcgi\_path\_info;  
fastcgi\_param PATH\_TRANSLATED $document\_root$fastcgi\_script\_name;  
include fastcgi.conf;  
}

This does not:  
location = /somedir/file1.php {  
try\_files @cache =404;  
}

Posted at Nginx Forum:

> **[Re: Location not called properly](https://forum.nginx.org/read.php?2,217122,217174#msg-217174)**
>
> Hi all, I'm trying to call a location of this format: location = /somedir/file1.php { try\_files @cache =404; } location = /anotherdir/file2.php { try\_files @cache =404; } location @cache { try\_fil

---

<div class="post-metadata">

**Author:** ![teck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b2d939/32.png) [@teck](https://www.ruby-forum.com/u/teck)\
**Post date:** [October 24, 2011, 10:13pm UTC](https://www.ruby-forum.com/t/location-not-called-properly/213098/4 "2011-10-24T22:13:16Z")

</div>

On Mon, Oct 24, 2011 at 07:02:35AM -0400, TECK wrote:

Hi there,

> The fastcgi value is the name of my upstream.

Yes, that part works.

> The idea is: once the location /somedir/file1.php is reached,  
> everything in @cache should execute.

If you _really_ want to do it that way, it would be something like

```
try_files /no-such-file @cache;

```

But you probably don’t want to do it that way.

> In this way, I don’t repeat several times the same code.

If you don’t want to _see_ lots of repetition in nginx.conf, use  
“include”.

If you don’t want to _write_ lots of repetition in nginx.conf, use a  
separate generator to create it.

> This works:
> 
> location /somedir/file1.php {

This will match “/somedir/file1.php”, and “/somedir/file1.phpX”, and  
“/somedir/file1.php/X”, for any X.

Although later config will likely block anything except  
“/somedir/file1.php” from being processed.

> This does not:  
> location = /somedir/file1.php {

This will match only “/somedir/file1.php”.

> try\_files @cache =404;

This will serve the file “/usr/local/nginx/html@cache”, or else  
return 404. (try\_files tries files. Only the last parameter is handled  
specially.)

Either make it “try\_files /no-such-file @cache;”, or replace it with  
“include my-repeated-php-config-file;”

Good luck,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
