Forum: Rails deployment Capistrano and nginx

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.
(Guest)
on 2007-07-01 11:53
(Received via mailing list)
I'm using nginx with capistrano to deploy my Rails app and I'm having
a hard time getting the maintenance capistrano task
(deploy:web:disable) to work like I want. I want nginx to redirect all
requests to public/maintenance-on.html if the file exists, however,
since I use stylesheets and images on this file, nginx should serve
them. Here's what I have so far on nginx.conf:

if (-f $document_root/public/maintenance-on.html) {
  rewrite ^(.*)$ /maintenance-on.html last;
  break;
}

How could I make this not match urls containing /stylesheets/ and /
images/?

Thanks in advance
(Guest)
on 2007-07-02 21:05
(Received via mailing list)
The rewrite directive you pasted means all requests will be rewritten
which would include stylesheets and images.  Just make sure this
directive appears in your nginx configuration before the part where
you serve static files or proxy to mongrel.

What you have written says:

'if the file $document_root/public/maintenance-on.html exists rewrite
ALL requests to serve the maintenance-on.html page'

Richard.
(Guest)
on 2007-07-03 00:58
(Received via mailing list)
Richard,

That was actually the first thing I tried, but even adding the
maintenance after the rule that make nginx serve statics files the
maintenance always comes first.
Eli M. (Guest)
on 2007-11-29 23:18
removed_email_address@domain.invalid wrote:
> (deploy:web:disable) to work like I want. I want nginx to redirect all
> requests to public/maintenance-on.html if the file exists, however,
> since I use stylesheets and images on this file, nginx should serve
> them.

Here is a solution I've used before:

  if (-f $document_root/system/maintenance.html) {
    set $maintenance 1;
  }
  if ($request_uri ~* (jpg|jpeg|gif|js|css)$) {
    set $maintenance 0;
  }
  if ($maintenance) {
    rewrite  ^(.*)$  /system/maintenance.html last;
    break;
  }

You can change the regex that $request_uri is matched against to match
your site quite easily.
D. K. (Guest)
on 2008-02-19 00:43
or you can also put your pictures and css on a different server ;)
I struggled with this for too many hours and couldn't make it work.. not
even with the xample from Eli.. The problem was that assets were
requested from a rul that wasn't exact (one level above etc. - depending
on what the original request was).. Maybe I should try again, but for
now I'm happy with my stupid solution.

Eli M. wrote:
> removed_email_address@domain.invalid wrote:
>> (deploy:web:disable) to work like I want. I want nginx to redirect all
>> requests to public/maintenance-on.html if the file exists, however,
>> since I use stylesheets and images on this file, nginx should serve
>> them.
>
> Here is a solution I've used before:
>
>   if (-f $document_root/system/maintenance.html) {
>     set $maintenance 1;
>   }
>   if ($request_uri ~* (jpg|jpeg|gif|js|css)$) {
>     set $maintenance 0;
>   }
>   if ($maintenance) {
>     rewrite  ^(.*)$  /system/maintenance.html last;
>     break;
>   }
>
> You can change the regex that $request_uri is matched against to match
> your site quite easily.
This topic is locked and can not be replied to.