Welcome! Log In Create A New Profile

Advanced

Re: Try_files and location blocks

António P. P. Almeida
June 24, 2011 02:52PM
On 24 Jun 2011 19h14 WEST, dave@jetcafe.org wrote:

> appa@perusio.net writes:
>> Also your later config could be simplified:
>> server {
>> ...
>> location / {
>> try_files $uri $uri/ /error.php?c=404 =404;
>> }
>> }
>
> In this case, it seems to me that try files is looking for a file
> named "/error.php?c=404" and not "/error.php". Try_files does not
> appear to strip the arguments from the uri when trying. My evidence
> for this is this debug line:
>
> 2011/06/24 03:11:58 [debug] 20773#0: *1 try to use file:
> "/error.php?c=403?" "/home/www/testhome/error.php?c=403?"

No. It doesn't. Check the code. It tries a named location otherwise
invokes ngx_http_split_args(). That's just a concise way of writing a
debug line in the error log.

> This means that I can't see if error.php exists before I try to
> throw an error with it. Right now it seems that my solution is:

Yes you can.

> location / {
> try_files $uri $uri/ =404;
> }
>
> location ~ .php$ {
> <..fastcgi stuff..>
> }
>
> error_page 404 = /error.php?c=404;
>
> location = /error.php {
> try_files /error.php @low_level_404
> <..the -same- fastcgi stuff as above..>
> }

This doesn't make sense. This is an exact location. It's entered from
a try_files, a rewrite or when you request that file directly. If the
file doesn't exist it signals a 404.

> location @low_level_404 {
> return 404;
> }
>
> I am really trying hard not to use "if" but I am weakening here
> because an "if" would let me use one and only one instance of
> fastcgi:
>
> location / {
> try_files $uri $uri/ =404;
> }
>
> location ~ .php$ {
> <..fastcgi stuff..>
> }
>

No need for an if. At least that's what I conclude from the previous
discussion. This should be all you need for the situation you
presented.

location / {
try_files $uri $uri/ /error.php?c=404 =404;
}

location = /error.php {
(...) # fastcgi stuff
}

> I'm also curious (in an academic way) as to what use case exists
> when try_files has to match url arguments as a filename? I usually
> strongly discourage the use of '?' and '&' characters in a filename.

You're taking the peculiar way the debug line is written as the real
way things are done.

Here's the relevant code from the http_core_module.c source (starting
at line 1241):

ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"try to use %s: \"%s\" \"%s\"",
test_dir ? "dir" : "file", name, path.data);

--- appa

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Try_files and location blocks

Dave Hayes June 23, 2011 05:38PM

Re: Try_files and location blocks

António P. P. Almeida June 23, 2011 06:04PM

Re: Try_files and location blocks

António P. P. Almeida June 23, 2011 06:12PM

Re: Try_files and location blocks

António P. P. Almeida June 23, 2011 06:20PM

Re: Try_files and location blocks

Dave Hayes June 23, 2011 06:30PM

Re: Try_files and location blocks

António P. P. Almeida June 23, 2011 06:48PM

Re: Try_files and location blocks

António P. P. Almeida June 23, 2011 07:02PM

Re: Try_files and location blocks

Dave Hayes June 24, 2011 02:16PM

Re: Try_files and location blocks

António P. P. Almeida June 24, 2011 02:52PM

Re: Try_files and location blocks

Dave Hayes June 24, 2011 07:04PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 155
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready