Setting up custom error pages are needed whenever the app goes in maintenance or when the code gets crashed :P … In Nginx, its fairly simple but once when you know it.

Say your app example.com is residing in /var/www/apps/example

Nginx configurations

say your existing configuration looks like…

  server{
      listen 80;
      server_name .example.com;
      location / {
           proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header Host $http_host;
           proxy_redirect false;
           proxy_pass http://127.0.0.1:9002;
      }
  }

add the error page configurations

  server{
      listen 80;
      server_name .example.com;
      location / {
           proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header Host $http_host;
           proxy_redirect false;
           proxy_pass http://127.0.0.1:9002;
      }
      error_page 500 502 503 504  /500.html;
      location = /500.html {
          root  /var/www/maintenance/example;
      }
  }

Create the required html error page at /var/www/maintenance/example/500.html.
Now, restart the nginx to reload the configurations by issuing /etc/init.d/nginx restart.
And you are done!

Please share your thoughts