The message came from a developer, not a monitor: every site on the dev server was down. Nobody had deployed anything. The cause was an automatic security update, because unattended upgrades restart services on their own, and one of those restarts took nginx down with it. Six hours passed between the failure and the fix.
Quick answer: on Ubuntu, unattended-upgrades installs security updates daily and then calls needrestart, which (from Ubuntu 24.04 LTS onward) restarts the services still using an old library. That keeps you patched, but services restart at a time you didn't choose. To stay in control, keep security updates on, run them in a window you pick, exclude critical services with $nrconf{override_rc}, and alert on failed services so you find out before your team does.
Why Unattended Upgrades Restart Services
unattended-upgrades is installed by default on Ubuntu and applies security updates once a day, with no one at the keyboard (Ubuntu Server docs). After it installs updates, it calls needrestart.
needrestart checks which running services still use a shared library that the update replaced. A patched library on disk doesn't protect a service that still has the old version loaded in memory. So needrestart restarts it.
The behavior changed in Ubuntu 24.04. Before that, needrestart only listed affected services when apt ran from a script. Canonical changed it so needrestart restarts them directly in both interactive and non-interactive runs, including unattended-upgrades (Ubuntu Discourse). Their argument: a service still running a vulnerable library isn't patched, whatever the package version says.
The catch is timing. In one published case, a single libc6 update restarted nginx, SSH, cron, journald and the DNS resolver in one batch, at whatever hour the timer fired.
How One Restart Took Every Site Down
Here is the chain from a client engagement, a dev server hosting several apps behind one nginx instance:
Unattended upgrades installed a security update.
needrestart restarted nginx.
One nginx virtual host proxied to an app using a public hostname instead of a local address.
At that moment, DNS lookups failed briefly.
nginx couldn't resolve the hostname, so it refused to start.
Every site on the server went down.
The first person to notice was a developer who couldn't reach their app. No alert fired. A colleague assumed one app was broken. It wasn't. All the sites shared one nginx instance, so a config error in one virtual host stopped the whole instance from starting.
A restart makes this worse than it sounds. systemctl restart stops nginx first, then runs the config test on start. When that test fails, nothing comes back. A reload behaves differently: if the new config fails, nginx keeps running the old one.
The fix took one line. The app ran on the same server, so the proxy never needed DNS:
Before (resolved through DNS every time nginx starts):
proxy_pass http://app.example.com;
After (same server, no DNS lookup; port is illustrative):
proxy_pass http://127.0.0.1:3000;We made it a standing rule for that client: when the app runs on the same host, nginx talks to it over 127.0.0.1.
Others have hit the same failure. In September 2025, an Ubuntu 24.04 user posted logs where a libc6 update made needrestart restart nginx and systemd-resolved together. nginx failed with host not found in upstream and stayed down until it was restarted by hand. The poster believed the resolver restarting at the same moment was the cause (Ubuntu Discourse). Another user on the needrestart thread described nginx staying in a failed state for almost 12 hours after an automatic restart, and suspected DNS too.
Why Nginx Fails With "Host Not Found in Upstream" After an Update
When proxy_pass points to a fixed hostname, nginx resolves it while loading the config. If the lookup fails, the config test fails and nginx won't start. That's the [emerg] host not found in upstream line in your logs.
On a normal day, DNS answers and you never see it. During an update, the resolver can be restarting at the same moment as nginx, and that small gap is enough.
Two ways to remove the risk:
Same server: use the local address. If the upstream runs on the same machine, point to 127.0.0.1 and a port. There's nothing to resolve.
Remote host: resolve while running. When proxy_pass contains a variable and the name isn't a defined upstream group, nginx resolves it through the resolver you configure, instead of at startup (nginx docs). If DNS is down, requests to that upstream fail, but nginx stays up and your other sites keep serving.
An illustrative config, assuming the host uses the systemd-resolved stub at 127.0.0.53:
location / {
resolver 127.0.0.53;
set $backend api.example.com;
proxy_pass https://$backend;
proxy_ssl_server_name on;
proxy_ssl_verify on;
proxy_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
}The last three lines matter for HTTPS upstreams: nginx doesn't send SNI or verify the upstream certificate by default. Run sudo nginx -t after any change, and test the routes on staging, because a variable in proxy_pass changes how the request URI is passed.
To find every place this could bite you:
grep -rn "proxy_pass" /etc/nginx/
How to Prevent Unattended Upgrades From Restarting Services
These settings control needrestart. They don't stop a package's own install scripts from restarting the service inside that package. Pick based on how much control you need.
1. Exclude a critical service. Keep automatic restarts for everything else, but leave one service for a planned restart. Drop a file into /etc/needrestart/conf.d/ rather than editing the main config:
echo '$nrconf{override_rc}{qr(^nginx\.service$)} = 0;' | sudo tee /etc/needrestart/conf.d/nginx.confThis adds one entry without replacing the default exclusion list. The service keeps running the old library until you restart it, so schedule that restart.
2. Switch needrestart to list-only mode. It reports what needs a restart and does nothing else:
#/etc/needrestart/conf.d/list-only.conf
$nrconf{restart} = 'l';Early Ubuntu 24.04 builds ignored this setting. The fix shipped in needrestart 3.6-7ubuntu4.1 in July 2024 (Launchpad bug 2068543), so check your package version. For a single manual run, the NEEDRESTART_MODE environment variable sets the mode: l to list, i for interactive, a for automatic.
3. Block specific packages. Add a package to Unattended-Upgrade::Package-Blacklist in /etc/apt/apt.conf.d/50unattended-upgrades and it won't upgrade automatically. Ubuntu's docs warn that this can also hold back other packages that depend on it, and a blocked core library stays unpatched. Review the list regularly.
4. Control when updates run. On the needrestart thread, a Canonical developer argues this is the right layer for production: control when updates install, rather than stopping services from restarting. The apt-daily-upgrade.timer decides when unattended upgrades run. To keep a daily cadence but pin it to a quiet hour:
sudo systemctl edit apt-daily-upgrade.timer[Timer]
OnCalendar=
OnCalendar=*-*-* 03:00
RandomizedDelaySec=0
Persistent=falseThe empty OnCalendar= clears the default schedule. Persistent=false stops a missed run from firing at the next boot, which keeps updates inside your window but means a server that was off skips that day. The time is server-local. apt-daily.timer, which refreshes package lists, is a separate timer. Confirm the result with systemctl list-timers apt-daily-upgrade.timer.
Avoid removing unattended-upgrades or needrestart outright. Package updates can still restart services through their install scripts without needrestart, so you keep surprise restarts and lose the library checks.
A Production-Safe Unattended Upgrades Setup
For small teams running their own Ubuntu servers, this is the setup we'd start with:
Keep automatic security updates on. By default they come from Ubuntu's release and security sources (plus ESM where available), not -updates, -proposed or -backports.
Run them at an hour you've chosen.
Exclude the few services that need a controlled restart, and restart them yourself soon after.
Turn on email reports: Unattended-Upgrade::Mail "ops@example.com"; and Unattended-Upgrade::MailReport "only-on-error";. This needs a working mail client such as ssmtp, and it reports package failures, not whether your apps are healthy.
Read /var/log/unattended-upgrades/ after runs. The unattended-upgrades-dpkg.log file shows which services needrestart tried to restart.
Use sudo unattended-upgrade -v --dry-run to check which packages would upgrade. It doesn't test whether services restart cleanly, so try real upgrades on staging first.
Leave Unattended-Upgrade::Automatic-Reboot off (it's off by default) and plan kernel reboots yourself.
Your Developers Should Not Be Your Outage Alert
The restart caused the outage. The missing alert made it last six hours.
At a minimum, every server that hosts customer-facing or team-facing apps needs:
An external uptime check on each public site, so you know when users can't reach it.
An alert when a systemd service enters a failed state, especially nginx.
Someone who gets that alert at night, not a shared inbox.
In a separate engagement, centralized monitoring and alerting was part of our work for ZenithTech, alongside server hardening and CI/CD stabilization (ZenithTech DevOps case study). Updates are a planned change, so treat them like a deploy: know what changed, watch what broke, and have a way back. Our release rollback checklist covers the deploy side of that habit.
When to Bring In Outside Help
Most teams can make these changes themselves: one needrestart drop-in file, one timer override, one mail setting, and a review of every proxy_pass line that points at a hostname.
Outside help makes sense when you run many servers with different owners, when nobody is sure which services can safely restart, or when an outage like this already happened and you don't know what else is waiting. We review patching, nginx configs and alerting through our DevOps consulting and automation services, and if a few config changes are all you need, we'll tell you that.
Frequently Asked Questions
Does unattended-upgrades restart services automatically?
Yes, on Ubuntu 24.04 and later. After installing updates, unattended-upgrades calls needrestart, which restarts affected services that still use an outdated library. Services on its built-in exclusion list, such as the display manager, are skipped.
How do I stop unattended upgrades from restarting services on Ubuntu?
Add a file to /etc/needrestart/conf.d/ that either excludes specific services with $nrconf{override_rc} or sets $nrconf{restart} = 'l' to list affected services without restarting them. Then restart those services yourself. A package's own install scripts can still restart its service.
Should I disable unattended upgrades on production servers?
Usually not, unless another process installs security fixes on time. A better setup keeps security updates on, runs them at a chosen hour, excludes services that need a controlled restart, and alerts on failures.
Why did nginx fail to start after an update?
One documented cause: nginx tried to resolve a hostname in proxy_pass while DNS was unavailable, for example while the resolver itself was restarting. nginx treats that as a config error and won't start. Use 127.0.0.1 for local upstreams, or a variable with a resolver for remote ones.
Does unattended-upgrades reboot the server?
Not by default. Unattended-Upgrade::Automatic-Reboot is false unless you turn it on, so kernel updates wait for a reboot you schedule.
Stay patched. Control restarts. Protect uptime.

