2
0
mirror of https://github.com/tmiland/Nginx-Maintenance-Mode synced 2024-11-09 17:59:42 +01:00
Easily toggle on or off maintenance mode with nginx
Go to file
2019-03-31 15:30:49 +02:00
img Create maintenance.png 2019-03-28 19:51:56 +01:00
.gitattributes Initial commit 2019-03-28 17:36:38 +01:00
LICENSE Initial commit 2019-03-28 17:36:38 +01:00
maintenance-page.conf Create maintenance-page.conf 2019-03-28 19:53:28 +01:00
maintenance.sh Update maintenance.sh 2019-03-31 14:59:35 +02:00
README.md Update README.md 2019-03-31 15:30:49 +02:00

Nginx Maintenance Mode

           _   __      _
          / | / /___ _(_)___  _  __
         /  |/ / __ `/ / __ \| |/_/
        / /|  / /_/ / / / / />  <
       /_/ |_/\__, /_/_/ /_/_/|_|
    	      /____/
    __  ___      _       __
   /  |/  /___ _(_)___  / /____  ____  ____ _____  ________
  / /|_/ / __ `/ / __ \/ __/ _ \/ __ \/ __ `/ __ \/ ___/ _ \
 / /  / / /_/ / / / / / /_/  __/ / / / /_/ / / / / /__/  __/
/_/  /_/\__,_/_/_/ /_/\__/\___/_/ /_/\__,_/_/ /_/\___/\___/

GitHub release licence Bash

Easily toggle on or off maintenance mode with nginx

Screenshots

screenshot

Installation

Download and execute the script:

$ git clone https://github.com/tmiland/Nginx-Maintenance-Mode.git
$ cd Nginx-Maintenance-Mode
$ cp -rp ./maintenance-page.conf /etc/nginx/snippets/
$ git clone https://github.com/alexphelps/server-error-pages.git /etc/nginx/html/server-error-pages
$ cp -rp /etc/nginx/html/server-error-pages/_site/maintenance-page.html /etc/nginx/html/server-error-pages/_site/maintenance-page_off.html
$ chmod +x maintenance.sh

Add to server directive

server {

## Nginx Maintenance Mode
include snippets/maintenance-page.conf;

}

Check for errors

$ nginx -t 
  • Add to each virtual server in /etc/nginx/sites-available you want to enable maintenance mode on.
  • Else, add to nginx.conf.

Usage

$ ./maintenance.sh [hostname] [on/off]

*** Note: [hostname] must match the hostname in your.hostname.com.conf/nginx.conf ***

E.G

server {
	server_name your.hostname.com;
  }
  • When maintenance mode is toggled on, maintenance-page_off.html will be copied to $server_name-maintenance-page_on.html. E.g: your.hostname.com-maintenance-page_on.html
  • This way you can use this with multiple virtual servers, and easily toggle on/off maintenance mode individiually for each site.
  • Toggle off, deletes $server_name-maintenance-page_on.html

Advanced usage

$ ./maintenance.sh my.hostname.com on
$ ./maintenance.sh my-other.hostname.com on
$ ./maintenance.sh my.hostname.com off
$ ./maintenance.sh my-other.hostname.com off

Logic in maintenance-page.conf


if (-f /etc/nginx/html/server-error-pages/_site/$server_name-maintenance-page_on.html)
{
  return 503;
}
error_page 503 @maintenance;
location @maintenance
{
  rewrite ^(.*)$ /$server_name-maintenance-page_on.html break;
  root /etc/nginx/html/server-error-pages/_site;
}

  • If your.hostname.com-maintenance-page_on.html exists, a error 503 is returned.
  • If not, operation is back to normal.

Credits

Donations

  • PayPal me
  • [BTC] : 3MV69DmhzCqwUnbryeHrKDQxBaM724iJC2
  • [BCH] : qznnyvpxym7a8he2ps9m6l44s373fecfnv86h2vwq2

Web Hosting

Sign up for web hosting using this link, and receive $100 in credit over 60 days.

DigitalOcean

Disclaimer

*** Use at own risk ***

License

MIT License Image

MIT License