Welcome! Log In Create A New Profile

Advanced

Try_files and location blocks

Dave Hayes
June 23, 2011 05:38PM
Hello. :) Could someone please correct my understanding of location
blocks and try files? I'm trying to get http errors to be very graceful,
normally being handled by php but in extreme cases returning the proper
numeric error. For my example, just consider 404:

server {
...
try_files $uri $uri/ /error.php?c=404

error_page 404 = @error_404;
location @error_404 {
try_files /error.php @not_found;
rewrite ^ $scheme://$server_name/error.php?c=404
}
location @not_found {
return 404;
}
}

I'm not clear why this does not work. I rewrite the above example
as:

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

location /error.php {
try_files /error.php @not_found;
}

error_page 404 = @not_found;
location @not_found {
return 404;
}
}

and it appears to work. I think the downside of this is that
I have to have the location /error.php explicitly invoke php.

While I enjoy hacking at something, I also enjoy understanding something
just as well. So what am I confused about?

Thanks in advance.
--
Dave Hayes - Consultant - Altadena CA, USA - dave@jetcafe.org
>>> The opinions expressed above are entirely my own <<<

"That's a very dangerous lake, Nasrudin. People who swim in
it are always being found dead at the bottom."

"That's alright, friend", replied Nasrudin. "I'll keep well
away from the bottom..."



_______________________________________________
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: 197
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