Setup Nginx Maintenance Page

Nginx grows in popularity day by day. Its solid performance and ease of setup make it a perfect tool to proxy traffic to your backend. In this article I will describe how you can configure a maintenance page that will be shown automatically every time you re-deploy or possibly your backend goes belly up.

If you already have an Nginx installation you can jump straight here. Otherwise I will guide you into installing Nginx as well. As usual, I will describe the installation procedure for CentOS 7. You can use the same procedure for any Fedora base distro.

Install Nginx

Recommended Folder Structure for Configuration Files

We create configuration files in the sites-available folder. We activate configurations by symlinking them in the sites-enabled folder.

I will describe the content of the mydomain-com.conf later on. For now we just add the following line in /etc/nginx/nginx.conf to instruct it to scan our site-enabled folder when launching up.

Proxy Pass and Maintenance Page

This is the content of our site specific configuration file.

As you can see the trick is simple. Proxy all requests to your backend except those hitting the /offline URL.

When your backend is down, Nginx will receive a 503 Service Unavailable error for which you instruct Nginx to display the offline.html file stored in /var/www/offline.

That’s all folks!