# Conflict: index and try\_files

**URL:** <https://www.ruby-forum.com/t/conflict-index-and-try-files/214010>\
**Category:** NGINX\
**Created:** [November 18, 2011, 3:39pm UTC](https://www.ruby-forum.com/t/conflict-index-and-try-files/214010 "2011-11-18T15:39:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [November 18, 2011, 3:39pm UTC](https://www.ruby-forum.com/t/conflict-index-and-try-files/214010/1 "2011-11-18T15:39:41Z")

</div>

In the following simple configuration

server {  
server\_name testsite.static;  
root /some/path/;  
index blog.html;  
try\_files $uri $uri.html =404;  
}

the try\_files directive seems to interfere with the index directive: I  
always get 404 for [http://testsite.static/](http://testsite.static/). If I remove the fallback  
part of try\_files, the same request results in an error:

\*990 rewrite or internal redirection cycle while internal redirect to  
"/.html.html.html…

The file blog.html is present in /some/path/, so I really do not  
understand why the file is not found/served for the above URL.

Posted at Nginx Forum:

> **[Conflict: index and try\_files](https://forum.nginx.org/read.php?2,218562,218562#msg-218562)**
>
> In the following simple configuration server { server\_name testsite.static; root /some/path/; index blog.html; try\_files $uri $uri.html =404; } the try\_files directive seems to interfere with the index directive: I always get 404 f

---

<div class="post-metadata">

**Author:** ![janedenone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/da6949/32.png) [@janedenone](https://www.ruby-forum.com/u/janedenone)\
**Post date:** [November 18, 2011, 3:42pm UTC](https://www.ruby-forum.com/t/conflict-index-and-try-files/214010/2 "2011-11-18T15:42:47Z")

</div>

On Fri, Nov 18, 2011 at 09:39:05AM -0500, janedenone wrote:

> always get 404 for [http://testsite.static/](http://testsite.static/). If I remove the fallback  
> part of try\_files, the same request results in an error:
> 
> \*990 rewrite or internal redirection cycle while internal redirect to  
> "/.html.html.html…
> 
> The file blog.html is present in /some/path/, so I really do not  
> understand why the file is not found/served for the above URL.

try\_files $uri $uri/ $uri.html =404;

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![janedenone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/da6949/32.png) [@janedenone](https://www.ruby-forum.com/u/janedenone)\
**Post date:** [November 18, 2011, 3:47pm UTC](https://www.ruby-forum.com/t/conflict-index-and-try-files/214010/3 "2011-11-18T15:47:08Z")

</div>

Excellent, this works.

Thanks a lot.

Posted at Nginx Forum:

> **[Re: Conflict: index and try\_files](https://forum.nginx.org/read.php?2,218562,218567#msg-218567)**
>
> In the following simple configuration server { server\_name testsite.static; root /some/path/; index blog.html; try\_files $uri $uri.html =404; } the try\_files directive seems to interfere with the index directive: I always get 404 f

---

<div class="post-metadata">

**Author:** ![janedenone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/da6949/32.png) [@janedenone](https://www.ruby-forum.com/u/janedenone)\
**Post date:** [November 18, 2011, 3:50pm UTC](https://www.ruby-forum.com/t/conflict-index-and-try-files/214010/4 "2011-11-18T15:50:51Z")

</div>

Hello!

On Fri, Nov 18, 2011 at 09:39:05AM -0500, janedenone wrote:

> always get 404 for [http://testsite.static/](http://testsite.static/).  
> If you want try\_files to test directories as well (and to allow  
> index directive to work), you have to explicitly specify “/” at  
> the end of name. I.e. use something like this:

try\_files $uri/ $uri $uri.html =404;

> If I remove the fallback  
> part of try\_files, the same request results in an error:

If you remove “=404” from the above try\_files, it will become

```
try_files $uri $uri.html;

```

i.e. if no file $uri found, it will redirect to $uri.html (/.html)  
in your case. In it’s turn it won’t be found and will again  
redirect to $uri.html (/.html.html now). The

> \*990 rewrite or internal redirection cycle while internal redirect to  
> "/.html.html.html…

is expected.

> The file blog.html is present in /some/path/, so I really do not  
> understand why the file is not found/served for the above URL.

That’s because it tests for files, and rejects directories by  
default. Test for directories must by explicitly requested.

See here for more information:

> **[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files)**
>
> This directive appeared in version 1.11.8.

Maxim D.

---

<div class="post-metadata">

**Author:** ![janedenone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/da6949/32.png) [@janedenone](https://www.ruby-forum.com/u/janedenone)\
**Post date:** [November 22, 2011, 2:56pm UTC](https://www.ruby-forum.com/t/conflict-index-and-try-files/214010/5 "2011-11-22T14:56:46Z")

</div>

Thanks again for the helpful hint. I noticed that it seems to be  
possible to remove the $uri part –

try\_files $uri/ $uri.html =404;

– and URLs like /image.jpg, /style.css etc are still found. I would  
expect that these requests return 404, because nginx tries image.jpg/  
and then image.jpg.html, but not the actual $uri. Am I missing  
something?

Posted at Nginx Forum:

> **[Re: Conflict: index and try\_files](https://forum.nginx.org/read.php?2,218562,218744#msg-218744)**
>
> In the following simple configuration server { server\_name testsite.static; root /some/path/; index blog.html; try\_files $uri $uri.html =404; } the try\_files directive seems to interfere with the index directive: I always get 404 f
