Welcome! Log In Create A New Profile

Advanced

Re: Use try_files and still get errors 404

Maxim Dounin
June 13, 2011 04:46PM
Hello!

On Mon, Jun 13, 2011 at 05:10:19AM -0400, iko wrote:

> Hello,
>
> recently I migrate one of domains, I manage, to use try_files directive
> instead of several "if" blocks and rewrites. New server description is
> like this:
>
> server {
> listen X.X.X.X;
> server_name example.com *.example.com;
>
> index index.php;
> root /www/example.com/www/root;
>
> try_files $uri $uri/ /index.php$is_args$args;
>
> location ~* \.(jpg|jpeg|gif|png|ico|swf)$ {
> gzip off;
> expires 7d;
> }
> location ~* \.(js|css)$ {
> expires 7d;
> }
> location ~ \.php$ {
> fastcgi_pass upstreanphp;
> fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
> fastcgi_intercept_errors on;
> fastcgi_read_timeout 120;
> fastcgi_next_upstream error timeout invalid_header;
> include fastcgi_params;
> }
> }
>
> Strange thing (for me) is if I try some URL like
> http://example.com/path/to/non/existing/file.jpg (or any other extension
> from location checks) I receive error 404. Is this normal behavior ? I
> expect index.php to be open. I've tried to put try_files in location / {
> } , but effect is the same ? Do I have to put try_files in every
> location block ? Or this is some kind of bug ?

Directive try_files isn't inhereted from previous levels, and not
expected to. You've defined it at server level (which isn't
allowed per documentation, btw, but happens to work - this is
probably a bug, indeed) and this results in try_files being used
in an implicit location.

There are no try_files in other locations though, and the result
you see is expected. If you want try_files to be in other
locations - you have to place it there too.

Maxim Dounin

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

Use try_files and still get errors 404

iko June 13, 2011 05:10AM

Re: Use try_files and still get errors 404

Maxim Dounin June 13, 2011 04:46PM

Re: Use try_files and still get errors 404

iko June 14, 2011 04:06AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 143
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready