# Try\_files

**URL:** <https://www.ruby-forum.com/t/try-files/209821>\
**Category:** NGINX\
**Created:** [July 23, 2011, 7:06pm UTC](https://www.ruby-forum.com/t/try-files/209821 "2011-07-23T19:06:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [July 23, 2011, 7:06pm UTC](https://www.ruby-forum.com/t/try-files/209821/1 "2011-07-23T19:06:35Z")

</div>

On 23.07.2011 17:42, António P. P. Almeida wrote:

> > - 
> > 
> > ```
> > location ^~ /media/ {
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > # static
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > expires 30d;
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > error_page 404 = @joomla;
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > log_not_found off;
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > }
> > 
> > ```

> Wouldn’t the use of try\_files be preferable to error\_page?
> 
> - 
> 
> ```
> error_page 404 = @joomla;
> 
> ```
> 
> - 
> 
> ```
> try_files $uri $uri/ @joomla;
> 
> ```

I just copy/paste/paste/paste already working config fragment…

> From the little I know, try\_files does a stat() call while error\_page  
> is a special response. They both do an internal redirection. They run  
> on different phases. Is this correct? If so is there any rule of  
> thumb  
> for deciding when to use try\_files vs. error\_page 404.

As far I know, “try\_files $uri $uri/ @joomla;” directive  
and “error\_page 404 = @joomla;” with “log\_not\_found off;”

has the same behaviour, - this is written at russian documentation.  
[http://sysoev.ru/nginx/docs/http/ngx\_http\_core\_module.html#try\_files](http://sysoev.ru/nginx/docs/http/ngx_http_core_module.html#try_files)

As I can see in [http://nginx.org/en/CHANGES](http://nginx.org/en/CHANGES)  
try\_files first appeared in nginx 0.7.27, and last known bug  
with try\_files was fixed in nginx 0.8.39, so in older versions  
of nginx error\_page 404 with log\_not\_found off; may be better,  
or may be the only one way to do such things.

and main purpose of try\_files - is just to be syntactic sugar  
for config files to be more clean and easy to read/understand.  
as in C language a[i] notation is syntactic sugar for \*(a + i)

–  
Best regards,  
Gena
