Forum: NGINX try_files... don't think I'm doing it right.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Phillip B Oldham (Guest)
on 2009-03-20 10:38
(Received via mailing list)
Attachment: phill.vcf (0 Bytes)
Hey all.

I'm trying to set-up an installation of zine, the python wordpress
clone. I've set it to run as fast-cgi through a socket, but after a
while it just flakes out. I'll get around to fixing that soon, but in
the meantime I'd like nginx to fallback to showing a "maintenance" html
page.

Here's my config:

server {
       listen 80;
       server_name mysite.com;
       error_page 500 502 503 504  /maintenance.html;
       location / {
               try_files @zine @fallback;
       }
       location @zine {
                include conf/fastcgi_params;
                fastcgi_param PATH_INFO $fastcgi_script_name;
                fastcgi_param SCRIPT_NAME "";
                fastcgi_pass unix:/tmp/mysite.socket;
       }
       location @fallback {
               root /var/www/mysite;
               index maintenance.html;
       }
}

This automatically falls-back, even though the instance is running.

What am I doing wrong?
Igor S. (Guest)
on 2009-03-20 11:04
(Received via mailing list)
On Fri, Mar 20, 2009 at 08:25:51AM +0000, Phillip B Oldham wrote:

> server {
>                fastcgi_pass unix:/tmp/mysite.socket;
>       }
>       location @fallback {
>               root /var/www/mysite;
>               index maintenance.html;
>       }
> }
>
> This automatically falls-back, even though the instance is running.
>
> What am I doing wrong?

The try_files test files existance and fallback to last parameter.
As there is no @zine file it always goes to @fallback.
You config should be

server {
      listen 80;
      server_name mysite.com;

      error_page 500 502 503 504  /maintenance.html;

      location / {
               include conf/fastcgi_params;
               fastcgi_param PATH_INFO $fastcgi_script_name;
               fastcgi_param SCRIPT_NAME "";
               fastcgi_pass unix:/tmp/mysite.socket;

               fastcgi_intercept_errors  on;
      }

      location = /maintenance.html {
              root /var/www/mysite;
      }
}
Phillip B Oldham (Guest)
on 2009-03-20 11:16
(Received via mailing list)
Attachment: phill.vcf (0 Bytes)
Igor S. wrote:
>       location / {
>       }
> }
>
Ah ha! Didn't spot the fastcgi_intercept_errors in the config docs when
I first tried a similar config. Is there a reason why its not "on" by
default?
Igor S. (Guest)
on 2009-03-20 11:29
(Received via mailing list)
On Fri, Mar 20, 2009 at 09:06:11AM +0000, Phillip B Oldham wrote:

> >
> >              root /var/www/mysite;
> >      }
> >}
> >
> Ah ha! Didn't spot the fastcgi_intercept_errors in the config docs when
> I first tried a similar config. Is there a reason why its not "on" by
> default?

I mistaked, in case of 502 and 504 errors, you do not need
fastcgi_intercept_errors as these errors come from nginx: it could not
connect(), timeout, etc. However, if your backend returns 502/504
then fastcgi_intercept_errors is required.

fastcgi_intercept_errors is off by default, because it does not affect
on nginx's 502/504 and you may want to show your own backend pages for
500/404/etc.
This topic is locked and can not be replied to.