Correct way to setup maintenance page in nginx

António P. P. Almeida appa at perusio.net
Thu Nov 3 21:02:11 UTC 2011


On 3 Nov 2011 20h18 WET, i at vbart.ru wrote:

> On Thursday 03 November 2011 22:30:00 Quintin Par wrote:
> [...]
>> This method outside of `location` directive
>>
>> error_page 503 /var/www/during_build.html;
>>
>> ## System Maintenance (Service Unavailable)
>> if (-f  /var/www/during_build.html) {
>> return 503;
>> }
>>
>> Is also not working. Nginx just returns 503 without the custom
>> page.
>>
>> What is the correct way to show system down pages?
>>
>
> Try this one:
>
> error_page 503 /during_build.html;
>
> location / {
>
> if (-f /var/www/during_build.html) {
> return 503;
> }
>
> }
>
> location = /during_build.html {
> root /var/www/;
> internal;
> }

Why not this?

root /var/www;

location / {

   error_page 503 @unavailable;

   location @unavailable {
      try_files /during_building.html @503;
   }
}

location @503 {
   return 503;
}

No need to use the if and the internal is implicit on the try_files.

--- appa



More information about the nginx mailing list