2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Nginxでメンテナンスページの設定をする

Last updated at Posted at 2018-10-06

Nginxでメンテナンスページの設定をする

Nginxでメンテナンスページを表示する設定について

環境

  • OS
    • Ubuntu 16.04.4 LTS
  • nginx
    • nginx version: nginx/1.10.3 (Ubuntu)

設定

  • maintenance.htmlを配置する
    • /var/www/html/maintenance.html
  • 503レスポンスのときに動作を定義する
    • error_page 503 @maintenance;
  • @maintenanceの処理を定義する

    • rewrite ^(.*)$ /maintenance.html break;
  • maintenance.htmlのファイルが存在したら、503を返すように設定し、@maintenanceの処理を実行させる

    • メンテナンス時にmaintenance.html をセットする
if (-e /var/www/html/maintenance.html) {
      set $maintenance true;
}
if ($maintenance = true) {
      return 503;
}
/etc/nginx/sites-enabled/test.conf
  1 server {
  2   listen 80 default_server;
  3   listen [::]:80 default_server;
  4
  5   root /var/www/html;
  6   index index.html index.htm index.nginx-debian.html;
  7   server_name X.X.X.X;
  8   error_page 503 @maintenance;
  9
 10   if (-e /var/www/html/maintenance.html) {
 11         set $maintenance true;
 12   }
 13   if ($maintenance = true) {
 14         return 503;
 15   }
 16
 17   location / {
 18     try_files $uri $uri/ =404;
 19   }
 20
 21   location @maintenance {
 22     rewrite ^(.*)$ /maintenance.html break;
 23   }
 24 }
  • curlで叩くと以下がレスポンスがかえってきた
<html>
<p> This is Maintenance Page </p>
</html>
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?