Improvised NGINX Maintenance Page

Sometimes I need to do some maintenance work on a webserver and I want to inform the users about it. Most of my websites run behind a NGINX reverse proxy which makes it quite easy to serve a maintenance page from there. This has the advantage that the maintenance page will even be served when the backend server is completely offline.

I was looking for a way to serve a short message without the need of an additional HTML document. Luckily the rewrite module of NGINX implements the return statement which I can use to accomplish this.

Here is an example:

server {
    listen          80;

    location / {
        add_header Content-Type text/plain;
        return 200 "Down for maintenance. Will be back soon.";

    location /maintenance {
        return 503;

Unfortunately most browsers will throw an error when you return a string with another status code than 200. But for most of my use cases it is enough and if you need more flexibility you can always use an extra HTML document in combination with the return statement or the error_page statement.

Über Max Rosin

Fotograf, Informatikstudent und Blogger. Mehr zu mir, gibt es hier
Dieser Beitrag wurde unter Tech abgelegt und mit , , verschlagwortet. Setze ein Lesezeichen auf den Permalink.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.