Location not called properly

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:
http://forum.nginx.org/read.php?2,217122,217122#msg-217122

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

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:
http://forum.nginx.org/read.php?2,217122,217174#msg-217174

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

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