# Hi, is there a way to use nginx to publish the maintenance file

**URL:** <https://www.ruby-forum.com/t/hi-is-there-a-way-to-use-nginx-to-publish-the-maintenance-file/204866>\
**Category:** NGINX\
**Created:** [March 23, 2011, 4:35pm UTC](https://www.ruby-forum.com/t/hi-is-there-a-way-to-use-nginx-to-publish-the-maintenance-file/204866 "2011-03-23T16:35:58Z")\
**Posts on this page:** 8\
**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:** [March 23, 2011, 4:35pm UTC](https://www.ruby-forum.com/t/hi-is-there-a-way-to-use-nginx-to-publish-the-maintenance-file/204866/1 "2011-03-23T16:35:58Z")

</div>

I have a question, if I want to use nginx to main the maintenance file,  
and what’s the easiest way for me to change a web to maintained status  
when it’s in emergency?

another question, as you see, that twitter always has Over Capacity  
Page, and how to implement this? is there any need to nginx to read  
something and then redirect all the connection to over capacity page?

---

<div class="post-metadata">

**Author:** ![Space\_Lee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@Space\_Lee](https://www.ruby-forum.com/u/Space_Lee)\
**Post date:** [March 23, 2011, 4:39pm UTC](https://www.ruby-forum.com/t/hi-is-there-a-way-to-use-nginx-to-publish-the-maintenance-file/204866/2 "2011-03-23T16:39:44Z")

</div>

On 3/23/2011 6:35 PM, Space Lee wrote:

> I have a question, if I want to use nginx to main the maintenance file, and  
> what’s the easiest way for me to change a web to maintained status when it’s in  
> emergency?

try\_files /www/maintenance.html $uri $uri/

It will be better to return 503 in that case as well.

–  
Regards, Vitaly T.  
System A.  
U.S. +1 (206) 905-9939  
Russia +7 911 094-2035

---

<div class="post-metadata">

**Author:** ![Space\_Lee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@Space\_Lee](https://www.ruby-forum.com/u/Space_Lee)\
**Post date:** [April 7, 2011, 10:13am UTC](https://www.ruby-forum.com/t/hi-is-there-a-way-to-use-nginx-to-publish-the-maintenance-file/204866/3 "2011-04-07T10:13:56Z")

</div>

thanks, it works using try\_files, and I put it in the location / { }  
I try to setup 503 as you suggest, but I don’t know how to trigger the  
503  
status?

---

<div class="post-metadata">

**Author:** ![Space\_Lee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@Space\_Lee](https://www.ruby-forum.com/u/Space_Lee)\
**Post date:** [April 7, 2011, 10:20am UTC](https://www.ruby-forum.com/t/hi-is-there-a-way-to-use-nginx-to-publish-the-maintenance-file/204866/4 "2011-04-07T10:20:44Z")

</div>

So each time, if I want to change to a maintained status, I have to add  
this line to the nginx configuration file and then restart the config?  
Is there a simpler way, so that I don’t need to change the settings of  
the server.

---

<div class="post-metadata">

**Author:** ![Space\_Lee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@Space\_Lee](https://www.ruby-forum.com/u/Space_Lee)\
**Post date:** [April 7, 2011, 10:35am UTC](https://www.ruby-forum.com/t/hi-is-there-a-way-to-use-nginx-to-publish-the-maintenance-file/204866/5 "2011-04-07T10:35:37Z")

</div>

No not really.

First you could send the status code by dynamic (ex. php) maintrance  
file (I think this is a bad idea through…) Second you could do  
something like this:

try\_files/www/maintenance.html $uri $uri/ @maintrance;

location @maintrance {  
return 503;  
}

Am 07.04.2011 10:19, schrieb Space Lee:

---

<div class="post-metadata">

**Author:** ![Space\_Lee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@Space\_Lee](https://www.ruby-forum.com/u/Space_Lee)\
**Post date:** [April 7, 2011, 10:16am UTC](https://www.ruby-forum.com/t/hi-is-there-a-way-to-use-nginx-to-publish-the-maintenance-file/204866/6 "2011-04-07T10:16:24Z")

</div>

Hello!

To return a http status simply add “return STATUS\_CODE;” to your config  
location. So to return a 503 type:

return 503;

MfG

Am 07.04.2011 10:13, schrieb Spacelee:

---

<div class="post-metadata">

**Author:** ![Space\_Lee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@Space\_Lee](https://www.ruby-forum.com/u/Space_Lee)\
**Post date:** [April 7, 2011, 12:41pm UTC](https://www.ruby-forum.com/t/hi-is-there-a-way-to-use-nginx-to-publish-the-maintenance-file/204866/7 "2011-04-07T12:41:44Z")

</div>

Hi, a strange thing, I found try\_files won’t work in the server context,  
only work in the location context.

I have a sample like this  
try\_files /maintenance.html $uri $uri/  
location / {  
XXXX  
}

then it won’t work, but if I move the try\_files into the location

location / {  
try\_files /maintenance.html $uri $uri/  
XXXX  
}

then it works for root directory.

and it’s a trouble that I have to put the try\_files in each location, as  
I have .php, .jpg location.  
location ~ .php$ {  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_index index.php;  
include fastcgi\_params;  
}

And I have to add the try\_files in each of the location, is there any  
better solution.

I try to put the try\_files out of the location, restarting nginx won’t  
have any error, but it won’t work when I access the site in the web  
browser.

---

<div class="post-metadata">

**Author:** ![Space\_Lee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@Space\_Lee](https://www.ruby-forum.com/u/Space_Lee)\
**Post date:** [April 7, 2011, 12:52pm UTC](https://www.ruby-forum.com/t/hi-is-there-a-way-to-use-nginx-to-publish-the-maintenance-file/204866/8 "2011-04-07T12:52:15Z")

</div>

Hello!

On Thu, Apr 07, 2011 at 06:41:05PM +0800, Space Lee wrote:

> location / {  
> try\_files /maintenance.html $uri $uri/  
> XXXX  
> }
> 
> then it works for root directory.

Yes, this is expected behaviour. Directive “try\_files” isn’t  
inherited and only make sense at server level if there is no  
matching location (that is, if implicit server location used to  
process request).

Maxim D.
