Understanding location blocks and try files

Francis Daly francis at daoine.org
Wed Jan 22 20:36:36 UTC 2014


On Wed, Jan 22, 2014 at 02:54:35PM -0500, AD7six wrote:

Hi there,

>     location ~ \.php$ {
>     location ~* \.(?:manifest|appcache|html?|xml|json)$ {

> A valid response where the url is a file:
> 
> $ curl -i http://nginx.dev/foo.json
> HTTP/1.1 200 OK

> An invalid response when passed to php:
> 
> $ curl -i http://nginx.dev/apples.json
> HTTP/1.1 404 Not Found

Why do you think that this request is passed to php?

> Am I missing something obvious or falling for a common misunderstanding?

One request is handled in one location.

The request "/apples.json" is handled in the second location above. Which
says (by omission of any other directive) "serve it from the file system
or return 404".

The error_page for 404 is also handled in that location, and the
appropriate file is found and returned.

> Is there a way to define location blocks for static files - without that
> causing problems for dynamic requests for the same url pattern?

"location" matches the uri. "static file" or "dynamic request" is
irrelevant at that point.

So "no"; but also "probably", depending on what exactly you want to do.

(The general suggestion in nginx is to use prefix-match locations at
the top level, not regex-match ones.)

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list