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
on 01.07.2007 09:53
on 02.07.2007 19:05
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.
on 02.07.2007 22:58
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.
on 29.11.2007 22:18
toulax@gmail.com 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.
on 18.02.2008 23: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 Miller wrote: > toulax@gmail.com 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.