1. TOP
  2. プログラミング
  3. Webサイトのメンテナンスモードの画面を出す方法と開発者だけ見れるようにする方法【Apache】

Webサイトのメンテナンスモードの画面を出す方法と開発者だけ見れるようにする方法【Apache】

 2018/10/09 プログラミング
この記事は約 5 分で読めます。 15,256 Views

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1434

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1434

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1434

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1434

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1434

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1434

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1434

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1434

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1451

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1451

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1451

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1451

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1451

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1451

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1451

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1451

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1216

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1216

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1216

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1216

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1216

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1216

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1216

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1216

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1226

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1226

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1226

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1226

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1226

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1226

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1226

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1226

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1239

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1239

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1239

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1239

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1239

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1239

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1239

Warning: Undefined array key 3 in /home/octo8/dainamo.jp/public_html/wp/wp-content/themes/surfing/lib/table-of-contents-plus/surfing_toc.php on line 1239

新規公開であれば問題はないことが多いですが、

別サーバーなどで開発をしていて、改修分を本番公開するときなど

すでに公開しているサイトで利用しているユーザーがいる場合には、

データの不整合など不具合が出てしまうため、ユーザーには触ってほしくない時ありますよね

そういう時は、メンテナンスモードにしてユーザーが触れないようにして反映することが必要になってきます。

今回は、Apache環境でメンテナンスモードの設定の仕方を書いて行きます。

また、開発者自身は触ることができるように設定します。

メンテナンスモードの設定

メンテに表示するページの作成

まずはメンテナンスモードにした時に表示するページを作成します

vi /var/www/html/maintenance.html

内容は自由に書いてください
今回は、例で以下のように書きました。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>メンテナンス中です</title>
    </head>

<body>
    <div style="width:950px; margin:0 auto; background-color:#FFF; padding:50px 0;">
        <p style="text-align:center; font-size:14px; color:#00A0E7;">
            メンテナンス中です
        </p>
        <p style="text-align:center; padding:25px 0;">
            申し訳ございません。只今メンテナンス中です。<br />
            メンテナンスの終了は午前01:00を予定しております。
        </p>
        <address style="font-style:normal; color:#666; font-size:12px; text-align:center;">
        2018 TEST
        </address>
    </div>
</body>
</html>

設定ファイルを作成する

ディレクトリを作成します

mkdir
/etc/httpd/conf.d/mainte

ディレクトリ内に設定ファイルを作成

vi /etc/httpd/conf.d/mainte/maintenance.conf
 ErrorDocument 503 /maintenance.html
 Alias /maintenance.html /var/www/html/maintenance.html
 
 RewriteEngine on
 RewriteCond %{REQUEST_URI} !=/maintenance.html
 RewriteCond %{REMOTE_ADDR} !=***.***.**.*** #許可するIP
 RewriteCond %{REMOTE_ADDR} !=127.0.0.1
 RewriteRule ^.*$ - [R=503,L]
 Header set Retry-After "Web, 26 Oct 2018 15:00:00 JST"

最下行の日時をメンテナンス終了日時に変更してください。

***.***.**.***に許可するIPアドレスを記載してください

静的IPアドレスではない場合

自分の使っているネット環境が静的IPアドレスでない場合は、IPアドレスを調べる方法がありますので、メンテナンスモードにする直前にでもIPアドレスを調べておきましょう

IPアドレスを調べる

バーチャルホストに設定ファイルを読み込み

バーチャルホスト、ssl.confに先ほどのmainte以下の設定ファイル
の読み込みを行います

/etc/httpd/conf.d/mainte/*.conf
vhost.conf ssl.conf
<VirtualHost *:80>
    ServerName test.jp
    DocumentRoot /var/www/html/test
    Include /etc/httpd/conf.d/mainte/*.conf
</VirtualHost>

Include 〜 でmainte以下のファイルを読み込んでいます

Apacheをリロード

リロードして反映させます

service httpd reload

メンテナンスモードが終了したらmaintenance.confをコメントアウトしてApacheをリロードしておきましょう

制作のご依頼・ご相談はこちら

dainamoでは魅力的なWEBサイトや、アプリ、ツール、ポスター、パンフレット、チラシなど幅広く承っております。ご相談、見積もり、お問い合わせなど、お気軽にご連絡ください。

今すぐご相談・問い合わせをする

\ SNSでシェアしよう! /

web制作・デザイン・システム開発・管理なら dainamo(ダイナモ)の注目記事を受け取ろう

この記事が気に入ったら
いいね!しよう

web制作・デザイン・システム開発・管理なら dainamo(ダイナモ)の人気記事をお届けします。

  • 気に入ったらブックマーク! このエントリーをはてなブックマークに追加
  • フォローしよう!

ライター紹介 ライター一覧

kz

kz

税金にも詳しいエンジニア

サーバーの構築からフロントエンド、iOSアプリの作成も行います。
WEBアプリや会員サービスの構築を得意としています。

制作物の一部を紹介
・海外旅行者向け事業者サービス
https://vacation-japan.com

・記憶術を使ったWEBアプリ会員サイト

その他、教育アプリetc..

この人が書いた記事  記事一覧

  • 【VPN】自宅のMacから会社のMacにリモートアクセスする場合のVPNの設定と画面共有方法【リモートデスクトップ】

  • Apacheのバージョン情報を隠してセキュリティを向上させる

  • 文字コードとは一体何なのか?MacでCSVの文字コードをUTF-8に変換する

  • 教師ありの機械学習(AI)プログラムを使用して、与えられた文章が何の言語なのか判定する

関連記事

  • フリーランスエンジニアが実際に使っている便利なフリーソフトツール2020

  • プログラミングで挫折した時に役立つエンジニア向けサイトまとめ2020

  • Linuxのプロンプトの色をユーザーによって切り分ける

  • 【html】selectタグの最初のoption(選択してください)を選ばせない方法

  • ボタンの2重クリックや連打を防止するJavaScript

  • 文字コードとは一体何なのか?MacでCSVの文字コードをUTF-8に変換する