Correct way to setup maintenance page in nginx

Hi all,

I tried using this method with try_files. Didn’t work. Also the HTTP
status code(503) is not being set.

location / {
    try_files /var/www/during_build.html @maintenance;
        proxy_pass  http://localhost:82;
}

location @maintenance {
      return 503;
}

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?

-Quintin

On Thursday 03 November 2011 22:30:00 Quintin P. wrote:
[…]

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;
}

wbr, Valentin V. Bartenev

On Friday 04 November 2011 01:02:11 Antnio P. P. Almeida wrote:

}
}

location @503 {
return 503;
}

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

First of all, named locations can be on the server level only.

And, how does a request get into @unavailable? Only after 503 has
occurred.
But, what will cause it?

I think the main idea was: when we need to do some maintenance, we just
create
a specific file (probably with explaining message for users) and Nginx
starts
to return 503 on every request.

wbr, Valentin V. Bartenev

On 3 Nov 2011 20h18 WET, [email protected] wrote:

location / {
}
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

On 11/3/11, Valentin V. Bartenev [email protected] wrote:

I think the main idea was: when we need to do some maintenance, we just
create
a specific file (probably with explaining message for users) and Nginx
starts
to return 503 on every request.

If you are willing to create some file for this you can just as well
swap
nginx.conf with special maintenance config, where you can specify a
single
server { } block with return 503 or anything you like.

Thanks Valentin. This worked like a charm.

I spend nearly 2-3 hours trying for a solution that evaded “if” and just
“try_files”. Even the official wiki supported that.

There are a lot of solutions out in the wild and most for them don’t
work.
Thanks again for the help.

-Quintin

On Friday 04 November 2011 01:54:02 Alexandr G. wrote:

If you are willing to create some file for this you can just as well swap
nginx.conf with special maintenance config, where you can specify a single
server { } block with return 503 or anything you like.

Of course, you have many options to do this with different pros and
cons.
And I just help to solve the problem the way that topic starter wants.

wbr, Valentin V. Bartenev

On second thought don’t you think the file check in the “if” condition
is
expensive considering it will be executed on every hit?

-Quintin

On Friday 04 November 2011 12:55:45 Quintin P. wrote:

On second thought don’t you think the file check in the “if” condition is
expensive considering it will be executed on every hit?

If you don’t deal with high-load or dedicated file storage with big
access
latency, then don’t worry. IMHO.

Also, you can try to tune Nginx open file cache:
http://nginx.org/en/docs/http/ngx_http_core_module.html#open_file_cache

wbr, Valentin V. Bartenev

Thanks.