The mainline nginx binary is not the problem — the configuration that arrived with it is. Ubuntu's nginx package ships an nginx.conf that loads every virtual host from /etc/nginx/sites-enabled inside its http block. The official nginx.org packages ship their own minimal nginx.conf that includes only /etc/nginx/conf.d/*.conf. Swap one for the other and your site files remain on disk, valid and untouched, but nginx never reads them.
What actually broke
Because only conf.d is loaded, nginx starts with a syntactically valid configuration that contains none of your server blocks. The service reports healthy, the error log stays quiet, and nginx -t passes — the configuration being tested is simply not the configuration you think you have. With no server block for your sites, nothing answers on the ports they expect. Direct clients connecting to a Let's Encrypt-secured site see the connection hang and time out. Cloudflare-proxied sites return error 525, which means Cloudflare could not complete a TLS handshake with your origin — exactly what happens when nothing is listening on 443.
The errors you saw when testing files in /etc/nginx/sites-enabled are a separate, harmless phenomenon: those files are fragments meant to be included inside an http block, so testing one as a standalone configuration complains about missing events and http sections. That is a red herring, not the fault.
Two packaging layouts, one silent difference
Debian and Ubuntu reshape nginx into a layout upstream does not use, and the two coexist quietly until you change package sources:
- Run user: the distro build runs workers as
www-data; upstream builds usenginx. - Virtual hosts: Debian-style installs keep site fragments in
/etc/nginx/sites-availableand symlink enabled ones into/etc/nginx/sites-enabled; upstream expects everything in/etc/nginx/conf.d/. - The include: Ubuntu's
nginx.confpulls inconf.d/*.confandsites-enabled/*from inside itshttpblock; the upstreamnginx.confpulls in conf.d only. - Dynamic modules: distro packages load them through
/etc/nginx/modules-enabled/*.conf; upstream packages ship modules separately and expect explicitload_moduledirectives.
Anything built on the Debian layout — your site files, provisioning scripts, muscle memory — keeps working right up to the moment the master config stops referencing it.
Confirming the diagnosis
You can prove it in seconds. Dump the effective configuration and search for the directory that is no longer included:
sudo nginx -T 2>/dev/null | grep -n "sites-enabled"
Empty output means none of those files are part of the running configuration. Then check what nginx is actually listening on:
sudo ss -tlnp | grep nginx
If your HTTPS ports are missing, no server block claims them. Together these checks rule out certificates, DNS, and proxy misconfigurations — the server is up; it just has no sites.
Fixing it
Add the missing include
The smallest fix is to teach the upstream nginx.conf about the Debian layout. Edit /etc/nginx/nginx.conf and add one line inside the http block, next to the existing conf.d include:
include /etc/nginx/sites-enabled/*;
Validate and reload:
sudo nginx -t && sudo systemctl reload nginx
Expect one behavioral flip: now that the fragments are actually loaded, latent syntax errors in them will surface for the first time. Fix whatever nginx -t reports — previously those files were being ignored, not validated.
Restore the Ubuntu nginx.conf
Copying a stock Ubuntu nginx.conf back from a snapshot, a backup file, or a clean install also works, with two checks. First, the line include /etc/nginx/modules-enabled/*.conf; must be emptied or removed unless the modules there were built for the new binary — dynamic modules are ABI-specific, and a distro-built module will abort startup with a binary-compatibility error. Second, user www-data; is fine on Ubuntu, but confirm /var/log/nginx remains writable by that user, or access and error logs will silently stop.
Migrate to conf.d
If you plan to stay on upstream packages long-term, consider moving each enabled site into /etc/nginx/conf.d/ as a .conf file and abandoning the sites-enabled workflow. That layout behaves identically on every nginx build and removes the trap entirely.
Preventing a repeat
- Snapshot
/etc/nginxbefore changing package sources — a tar archive or a git-tracked/etcmakes the old config trivially recoverable. - After any nginx package change, verify the effective configuration with
nginx -Tand request one URL per vhost before declaring success; a greensystemctl statusproves nothing about which files were loaded. - On new servers, prefer
conf.dfor site definitions if there is any chance you will switch between distro and upstream packages.
Frequently Asked Questions
Why did nginx -t pass while every site was down?
Because nginx -t validates the configuration that is loaded, and that configuration was valid — it just did not contain your sites. A syntax check cannot tell you a file is missing from the include set; use nginx -T to review what is actually in effect.
Why do my site files complain about missing events and http blocks when tested alone?
A file containing only a server block is a fragment. nginx requires events and http blocks in any top-level configuration, so testing a fragment directly always fails. The fragment is only valid where an http block includes it.
Should workers run as www-data or nginx?
Either works; the user directive only controls the identity workers use to read files and write logs. Pick one and make file and log ownership match it — mixing them is how logs quietly disappear.
Do I still need the modules-enabled include?
Only if the module packages in that directory were built for the nginx binary you now run. Comment the include out if you are not using those modules, or install upstream-built module packages instead.
Is Cloudflare error 525 specific to this problem?
No. Error 525 only means Cloudflare could not complete a TLS handshake with your origin. Any origin that stops listening on 443, drops packets, or presents broken certificates produces it. Here the cause was that no server block was listening at all.