nginx: Create HTTP 503 Maintenance Custom Page

www.laut‮rut‬i.com
nginx: Create HTTP 503 Maintenance Custom Page

To create a custom maintenance page for HTTP 503 errors in nginx, you can use the error_page directive in your nginx configuration file. This directive allows you to specify a custom page to be displayed when a particular HTTP error code is returned.

To create a custom maintenance page for HTTP 503 errors, you can add the following directive to your nginx configuration file:

error_page 503 /maintenance.html;
location = /maintenance.html {
  root /usr/share/nginx/html;
}

This will display the /usr/share/nginx/html/maintenance.html file when an HTTP 503 error is returned. You can create this file and customize its contents to display a maintenance message or any other content you wish to show to users during maintenance.

To enable the maintenance mode, you can use the return directive in your nginx configuration file to return an HTTP 503 error for all requests. For example:

server {
  listen 80;
  server_name example.com;
  return 503;
}

This will return an HTTP 503 error for all requests to example.com. When the maintenance is complete, you can disable the maintenance mode by removing the return 503 directive or commenting it out.

It is important to note that the error_page directive only works for HTTP errors returned by nginx. If you are using a backend application server (such as PHP-FPM, Gunicorn, or uWSGI), you will need to configure the application server to return the HTTP 503 error and display the maintenance page.

Created Time:2017-10-30 10:17:55  Author:lautturi