DEV Community

Jikwang Moon
Jikwang Moon

Posted on

Stop running an extra container for your maintenance page: doing it right at the reverse proxy

Sooner or later every self-hosted site needs one of these:

  • a maintenance page while the app is being upgraded or the database migrated,
  • a "coming soon" page for a domain you bought but haven't built yet,
  • a parked page for a domain you keep but don't use.

The common answer is "run a tiny nginx container with an index.html and point the proxy at it."
It works, but it's one more container to update, and it usually gets the details wrong: it answers
200 OK, so search engines index your maintenance notice, CDNs and browsers cache it, and uptime
monitors report the site as healthy while it's down.

The reverse proxy already terminates TLS for that domain. It can answer the page itself.

The details that matter

Use 503 for maintenance, not 200. 503 Service Unavailable tells crawlers "temporary, come back
later": Google keeps your existing pages in the index instead of replacing them with "We'll be back
soon". A Retry-After header (seconds or a date) is a hint for when to come back. For a domain that
will never serve anything, 410 Gone (or 404) is more honest than 200.

Don't let it be cached. Send Cache-Control: no-store with the maintenance response, or a CDN
or browser may keep showing it after you're back up.

Keep what still works reachable. Maintenance on the web app doesn't have to take down /api,
webhooks or your health checks. Serve the page on / and keep forwarding the paths that are fine.

Let yourself in. It's convenient if your own IP (or a header) still reaches the real backend so
you can test before you switch the page off.

Keep security on. The page answers for the whole domain, so TLS, rate limits and whatever
filtering you normally apply should still run in front of it.

Plain nginx

server {
    listen 443 ssl;
    server_name app.example.com;
    # ... certificates ...

    # keep the API and health checks up during maintenance
    location /api/ { proxy_pass http://app_backend; }

    location / {
        # let yourself in to test
        if ($remote_addr = 203.0.113.10) { proxy_pass http://app_backend; }
        return 503;
    }

    error_page 503 @maintenance;
    location @maintenance {
        root /usr/share/nginx/maintenance;
        add_header Cache-Control "no-store" always;
        add_header Retry-After 3600 always;
        try_files /index.html =503;
    }
}
Enter fullscreen mode Exit fullscreen mode

Two traps: add_header only applies to the response codes listed in its docs unless you add always
(503 isn't one of them), and if inside location is limited — fine for proxy_pass or return,
don't put much else in it.

Nginx Proxy Manager

NPM always proxies to a forward host, so the usual setup is the extra container. Without it, you can
put a custom location / in the proxy host's Advanced tab (NPM then skips its own) and use the
nginx snippet above — but the HTML has to exist inside the NPM container (mount a folder into
/data/ and point root there), and you edit it by hand.

Corvus

This is the setup that pushed me to build it into Corvus
(an open-source reverse proxy with a WAF, in one container): since 1.9 a proxy host can serve a
page
instead of forwarding.

  • Pick Parked, Coming soon or Maintenance, or paste your own HTML.
  • Choose the status: 200, 404, 410 or 503 (maintenance defaults to 503); anything but 200 is sent with Cache-Control: no-store.
  • TLS, security rules, rate limits and Basic auth keep applying; custom locations keep forwarding, so /api stays up while / shows the page.
  • Switching back to "forward to a service" is one click; the page is kept for next time.

Serve a page in Corvus

(It was suggested by a user in our GitHub Discussions, like most of what went into the last three
releases.)

Checklist

  • [ ] 503 + Retry-After for maintenance, 410/404 for domains that will never serve anything
  • [ ] Cache-Control: no-store on the maintenance response (always in nginx)
  • [ ] /api, webhooks and health checks still forwarded if they work
  • [ ] a way for you to reach the real backend while the page is up
  • [ ] TLS and your usual protections still in front of the page
  • [ ] no extra container to keep updated

What do you use for maintenance windows today? Curious whether people bother with 503 at all.

Top comments (2)

Collapse
 
posting-dude profile image
Posting Dude •

The add_header without always thing is such a quiet trap, the page looks fine in the browser and the headers just arent there. Does Corvus have a way to schedule the page on and off? For a solo dev forgetting to switch it back feels like a bigger risk than the status code.

Collapse
 
moonjikwang profile image
Jikwang Moon •

Agreed, that one bites because nothing looks wrong until you check the headers with curl.

No scheduling yet. Today switching is one click, or one API call, so you can put the "switch back" in cron or at the end of your deploy script: a PUT /api/proxy-hosts/{id} with "content": "forward", and the page itself is kept for next time.

But you're right that forgetting is the real risk for a solo dev. An "end at" time on the page (switch back to forwarding automatically, and show the time as Retry-After) would fit well. I'll open an issue for it.