Create A Maintenance Mode For Your Ghost Blog

If you’re using nginx to handle and route all the different Ghost blog instances on the same server, you can use Nginx also to show the visitors a maintenance page if your Node.js instance goes offline.

To catch the http error 502 – that’s the HTTP error code which occurs in that case – you create a HTML file (for example maintenance.html) in the root directory of your Ghost blog or wherever you want and add the following snippet to your Nginx host config where you want to have a maintenance page:

error_page 502 = /maintenance.html;
location /maintenance.html {
  access_log off;
  log_not_found off;
}

If the Node.js server goes offline, the HTML page will show!

If you’re running php-fpm on the server you can use a PHP script instead of a HTML file and could look like that:

error_page 502 = /maintenance.php;
location /maintenance.php {
  fastcgi_split_path_info  ^(.+.php)(.*)$;
  fastcgi_pass             unix:/var/run/php5-fpm.sock;
  fastcgi_index            index.php;
  fastcgi_param            PATH_TRANSLATED  $document_root$fastcgi_path_info;
  fastcgi_param            SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  fastcgi_param            SCRIPT_NAME      $fastcgi_script_name;
  fastcgi_intercept_errors off;
}

The PHP part settings could differ to yours!

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn