# Try\_files

**URL:** <https://www.ruby-forum.com/t/try-files/207179>\
**Category:** NGINX\
**Created:** [May 20, 2011, 12:10am UTC](https://www.ruby-forum.com/t/try-files/207179 "2011-05-20T00:10:02Z")\
**Posts on this page:** 4\
**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:** [May 20, 2011, 12:10am UTC](https://www.ruby-forum.com/t/try-files/207179/1 "2011-05-20T00:10:02Z")

</div>

I have a uwsgi\_app

I was wondering why

location / {  
root /myapp;  
index index.html index.wsgi;  
try\_files $uri $uri/ @wsgi;  
}  
;

When I visit the [domain.com](http://domain.com) returns a 403 (when I dont have an  
index.html file in the root directory);

but if I do [Domain.com](http://domain.com/index.wsgi)

The WSGI app is called. This all works.

I am guessing I am doing something wrong.

In my config I have

location @wsgi {  
include uwsgi\_params;  
uwsgi\_pass unix:/tmp/uwsgi.sock  
}

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [May 20, 2011, 12:23pm UTC](https://www.ruby-forum.com/t/try-files/207179/2 "2011-05-20T12:23:27Z")

</div>

Hello!

On Thu, May 19, 2011 at 06:10:04PM -0400, David J. wrote:

> location @wsgi {  
> include uwsgi\_params;  
> uwsgi\_pass unix:/tmp/uwsgi.sock  
> }

Please show full config.

Maxim D.

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [May 20, 2011, 12:57pm UTC](https://www.ruby-forum.com/t/try-files/207179/3 "2011-05-20T12:57:25Z")

</div>

Running Nginx v1.0.0

Here is server config

server {  
listen 80;  
server\_name [domain.com](http://domain.com) [www.domain.com](http://www.domain.com);  
location /{  
index index.html index index.htm index.php;  
root /www/domain.com;  
try\_files $uri $uri/ @wsgi;  
}

location @wsgi {  
index index.html index.htm;  
include uwsgi\_params;

uwsgi\_pass  
unix:/tmp/uwsgi.sock;  
}  
location  
~ .css$ {  
root /www/domain.com;  
}

}

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [May 20, 2011, 2:12pm UTC](https://www.ruby-forum.com/t/try-files/207179/4 "2011-05-20T14:12:46Z")

</div>

Hello!

On Fri, May 20, 2011 at 06:57:23AM -0400, David J. wrote:

> try\_files $uri $uri/ @wsgi;  
> }
> 
> }

It doesn’t looks like you have “index” directive set to  
“index.wsgi” nor any actual handling of index.wsgi (except  
try\_files fallback). This all makes me think that you actually  
don’t have index.wsgi on filesystem either.

Note that “index” directive will actually test existence of given  
index files on filesystem and will do an internal redirect if one  
was found. That is, if you don’t have any index files on  
filesystem - you’ll get 403 (unless autoindex module enabled).

The configuration you probably want is something like

```
root /www/domain.com;

location / {
    try_files $uri $uri/index.html @wsgi;
}

location @wsgi {
    uwsgi_pass ...
}

```

That is: if file exists, return it; if there is a directory with  
index.html, return it; else fallback to wsgi.

Maxim D.
