Skip to content
All insights
PracticeCloud

One hostname took down every site we run

Aaron WylieNovember 18, 20266 min read

nginx resolves proxy upstreams when it starts, and treats a failure as fatal. A storage bucket that did not exist yet stopped the web server booting, and nine unrelated sites went down with it.

We run a handful of sites on one small server. In October all of them went off at once and stayed off for two days. The cause was a hostname that did not resolve, in the config for a site none of the others had ever heard of.

It is worth writing up, because nothing about it was exotic and the same shape is sitting in a lot of nginx configs.

What happened

We were migrating a static site onto the box. Its larger files live in object storage, so its config proxies one path to a bucket:

location ^~ /media/ {
    proxy_pass https://example.sfo2.digitaloceanspaces.com/media/;
}

The config went in before the bucket was created. That ordering is the whole story.

nginx resolves the hostname in a literal proxy_pass once, when it starts, and treats a failure to resolve as a fatal configuration error. Not a warning. Not a 502 on that one path. It refuses to start at all.

So the next time nginx restarted, it did not come back, and not only for that site. For every site on the machine.

Why nobody noticed for two days

This is the part that actually cost us.

The daily summary we send ourselves reports page views. Throughout the outage it reported zero, and zero reads like a quiet day. Nothing in the mail said that nothing at all had been recorded, not even a crawler, which is a different and much louder statement.

We did have an uptime check. It ran on the same box.

Three fixes, in order of how much they matter

Stop a dead upstream being fatal. Put the hostname in a variable and give nginx a resolver. Resolution then happens per request rather than at boot:

location ^~ /media/ {
    resolver 127.0.0.53 ipv6=off valid=300s;
    set $upstream example.sfo2.digitaloceanspaces.com;
    proxy_pass https://$upstream$request_uri;
}

Note the $request_uri on the end. Once there is a variable in proxy_pass, nginx stops appending the matched path for you and you have to supply it yourself. Miss that and the prefix is silently stripped, which is a fun afternoon.

A DNS failure is now a 502 on one path, which is what it always should have been.

Put the monitor somewhere else. A check that shares a host with the thing it watches tells you nothing on the day it matters, because it dies in the same instant. Ours now runs as a scheduled job on a service we do not control, hitting every hostname and failing loudly.

Make silence noisy. Zero of everything is not a slow day. The daily mail now counts crawler traffic alongside human traffic and says so in the subject line when the total is nought, because a site that is up is never that quiet. Even with no visitors at all, something is always crawling.

The general version

Two things here generalise well beyond nginx.

The first is blast radius. Shared infrastructure means the config for the least important thing on the box can take down the most important thing on the box. That is a perfectly reasonable trade for the money it saves, but only if you know you have made it. We had never thought about it, which is not the same as having decided.

The second is ordering. Create the thing before you point at it. Almost every deployment sequence has one of these hiding in it: a DNS record, a bucket, a certificate, a database that a config file assumes already exists. Writing the config first is fine right up until something validates at boot and refuses to start without it.

A monitor running on the same machine as the service is a component of that service, not a check on it.

What we ask clients now

When we look at someone's hosting, the question is no longer just whether it is monitored. It is where the monitor runs, and what the alert looks like when the answer is nothing rather than something.

Ready to build something that lasts?

Tell us what you are trying to ship. We will tell you how we would approach it - scope, stack, and timeline - before you commit to anything.