Menu

Thursday 23 May 2019

Redirect traffic during maintenance or downtime using Apache.

Hi folks!
We have to redirect the traffic to the static HTML maintenance page,  during maintenance or downtime of the application using Apache server.

for this, we have to create a new static HTML maintenance page & maintenancepage.enable file.

   a. maintenancepage.html  
   b. maintenancepage.enable 
   c. Redirecting configurations in httpd.conf/ssl.conf file.


Step A: create a file "maintenancepage.html" and write below HTML code.

-----------------------------------------------------------------------------------

<!doctype html>
<title>Site Maintenance</title>
<style>
  body { text-align: center; padding: 150px; }
  h1 { font-size: 50px; }
  body { font: 20px Helvetica, sans-serif; color: #333; }
  article { display: block; text-align: left; width: 650px; margin: 0 auto; }
  a { color: #dc8100; text-decoration: none; }
  a:hover { color: #333; text-decoration: none; }
</style>

<article>
<h1>Application Name</h1>
    <h1>We&rsquo;ll be back soon!</h1>
    <div>
    <p>Sorry for the inconvenience but we&rsquo;re performing some maintenance at the moment. If you need to you can always <a href="mailto:#">contact us</a>, otherwise we&rsquo;ll be back online shortly!</p>
    <p>&mdash; The MiddlewareBox Team</p>
    </div>
</article>

-----------------------------------------------------------------------------------

Download the code from Github: https://gist.github.com/





Step B. Create a empty file called as "maintenancepage.enable" file.

This file is created to enable and disable maintenance page during no downtime, after configurations and restart of apache server.

If we delete the "maintenancepage.enable" file, it will not redirect the traffics.


NOTE IMP: Save both files in $APACHE_HOME/htdocs folder.

Step C.  Locate to $APACHE_HOME/conf folder and edit "httpd.conf" file and "httpd-ssl.conf", write below configurations.

------------------------------------------------------------------------------

LoadModule headers_module modules/mod_headers.so
LoadModule rewrite_module modules/mod_rewrite.so

RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
RewriteCond %{HTTP_HOST} !^localhost$ [NC]
RewriteCond %{DOCUMENT_ROOT}/maintenancepage.html -f
RewriteCond %{DOCUMENT_ROOT}/maintenancepage.enable -f
RewriteCond %{SCRIPT_FILENAME} !maintenancepage.html
RewriteRule ^.*$ /maintenancepage.html [R=503,L]
ErrorDocument 503 /maintenancepage.html
Header always Set Cache-Control "max-age=0, no-store" "expr=%{REQUEST_URI}=='/maintenancepage.html'"

------------------------------------------------------------------------------






Step D. Stop the application and check the redirection of apache to maintenancepage.html using browser.



Refrence:


Thanks :-)




No comments:

Post a Comment