# Not opening default site page via FastCGI and try\_files

**URL:** <https://www.ruby-forum.com/t/not-opening-default-site-page-via-fastcgi-and-try-files/174946>\
**Category:** NGINX\
**Created:** [September 4, 2009, 1:46pm UTC](https://www.ruby-forum.com/t/not-opening-default-site-page-via-fastcgi-and-try-files/174946 "2009-09-04T13:46:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![personxxl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/54ee81/32.png) [@personxxl](https://www.ruby-forum.com/u/personxxl)\
**Post date:** [September 4, 2009, 1:46pm UTC](https://www.ruby-forum.com/t/not-opening-default-site-page-via-fastcgi-and-try-files/174946/1 "2009-09-04T13:46:01Z")

</div>

Hi,

I use FastCGI and try\_files with Nginx.

FastCGI catches all url patterns and render appropriate page.

It works well for urls like  
[site.com/some-page](http://site.com/some-page)  
[site.com/index.htm](http://site.com/index.htm)  
[site.com/any-page.htm](http://site.com/any-page.htm)  
[site.com/any-wildcarded-page-name-at-all](http://site.com/any-wildcarded-page-name-at-all)

But it never works for site root  
[site.com/](http://site.com/)

I use try\_files.  
Can you point me how to make default site URL work?

This is my Nginx conf:

server\_name\_in\_redirect off;  
listen 80;  
server\_name ~^(www.)?(.+)$;  
root /var/www/$2/htdocs;

location / {  
try\_files $uri $uri/ $uri/index.htm @django;  
index index.html index.htm;  
}

location @django {  
fastcgi\_pass 127.0.0.1:8801;  
fastcgi\_param PATH\_INFO $fastcgi\_script\_name;  
fastcgi\_param REQUEST\_METHOD $request\_method;  
fastcgi\_param QUERY\_STRING $query\_string;  
fastcgi\_param SERVER\_NAME $server\_name;  
fastcgi\_param SERVER\_PORT $server\_port;  
fastcgi\_param SERVER\_PROTOCOL $server\_protocol;  
fastcgi\_param CONTENT\_TYPE $content\_type;  
fastcgi\_param CONTENT\_LENGTH $content\_length;  
fastcgi\_pass\_header Authorization;  
fastcgi\_intercept\_errors off;  
fastcgi\_param REMOTE\_ADDR $remote\_addr;  
}

Thanks.

---

<div class="post-metadata">

**Author:** ![personxxl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/54ee81/32.png) [@personxxl](https://www.ruby-forum.com/u/personxxl)\
**Post date:** [September 4, 2009, 2:13pm UTC](https://www.ruby-forum.com/t/not-opening-default-site-page-via-fastcgi-and-try-files/174946/2 "2009-09-04T14:13:22Z")

</div>

On Fri, Sep 04, 2009 at 01:46:01PM +0200, Ale Ru wrote:

> [site.com/any-wildcarded-page-name-at-all](http://site.com/any-wildcarded-page-name-at-all)  
> listen 80;  
> server\_name ~^(www.)?(.+)$;  
> root /var/www/$2/htdocs;
> 
> location / {  
> try\_files $uri $uri/ $uri/index.htm @django;  
> index index.html index.htm;  
> }

Try

location / {  
try\_files $uri $uri/index.htm @django;  
}

or

location / {  
try\_files $uri $uri/ @django;  
index index.htm index.html;  
}

---

<div class="post-metadata">

**Author:** ![personxxl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/54ee81/32.png) [@personxxl](https://www.ruby-forum.com/u/personxxl)\
**Post date:** [September 4, 2009, 2:31pm UTC](https://www.ruby-forum.com/t/not-opening-default-site-page-via-fastcgi-and-try-files/174946/3 "2009-09-04T14:31:51Z")

</div>

Igor S. wrote:

> On Fri, Sep 04, 2009 at 01:46:01PM +0200, Ale Ru wrote:
> 
> > [site.com/any-wildcarded-page-name-at-all](http://site.com/any-wildcarded-page-name-at-all)  
> > listen 80;  
> > server\_name ~^(www.)?(.+)$;  
> > root /var/www/$2/htdocs;
> > 
> > location / {  
> > try\_files $uri $uri/ $uri/index.htm @django;  
> > index index.html index.htm;  
> > }
> 
> Try
> 
> location / {  
> try\_files $uri $uri/index.htm @django;  
> }
> 
> or
> 
> location / {  
> try\_files $uri $uri/ @django;  
> index index.htm index.html;  
> }

This is what i have in nginx.conf. It works for all files except site  
root page.  
What is the difference from my original config? i tried both changes  
(delted $uri/ or delted $uri/index.htm) - the same effect.

when i type [domain.com/index.htm](http://domain.com/index.htm) (and there are no static index.htm  
page) i get the page from django FCGI script

when i type [domain.com/](http://domain.com/) (and there is a _static_ page called index.htm)  
i get static page

but when i type [domain.com/](http://domain.com/) (and there is no static page called  
index.htm) i get  
403 Forbidden  
nginx/0.7.61

---

<div class="post-metadata">

**Author:** ![personxxl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/54ee81/32.png) [@personxxl](https://www.ruby-forum.com/u/personxxl)\
**Post date:** [September 4, 2009, 3:09pm UTC](https://www.ruby-forum.com/t/not-opening-default-site-page-via-fastcgi-and-try-files/174946/4 "2009-09-04T15:09:34Z")

</div>

On Fri, Sep 04, 2009 at 02:31:51PM +0200, Ale Ru wrote:

> > > ```
> > > index index.html index.htm;
> > > 
> > > ```
> > 
> > location / {  
> > try\_files $uri $uri/ @django;  
> > index index.htm index.html;  
> > }
> 
> This is what i have in nginx.conf. It works for all files except site  
> root page.  
> What is the difference from my original config? i tried both changes  
> (delted $uri/ or delted $uri/index.htm) - the same effect.

The difference is only in order of file existance testing.

> when i type [domain.com/index.htm](http://domain.com/index.htm) (and there are no static index.htm  
> page) i get the page from django FCGI script
> 
> when i type [domain.com/](http://domain.com/) (and there is a _static_ page called index.htm)  
> i get static page
> 
> but when i type [domain.com/](http://domain.com/) (and there is no static page called  
> index.htm) i get  
> 403 Forbidden  
> nginx/0.7.61

Then you need

location @dajno {  
fastcgi\_index index.htm;  
…
