Common causes
- The same site is enabled twice, for example example.com and example.com.bak in sites-enabled
- Certbot added a server block while an old one with the same name still exists
- A name is listed in both the default server and a site file
- conf.d/*.conf and sites-enabled/* both include a copy of the site
- Two separate sites accidentally share a www or alias name
How to fix it
- Find every block using the name. Run sudo nginx -T 2>/dev/null | grep -n 'server_name.*example.com' to search the full loaded config. Note the file each match comes from.
- Remove duplicates and backups. Delete or move backup files out of /etc/nginx/sites-enabled/ and /etc/nginx/conf.d/. Nginx loads every matching file there, including .bak copies when the include uses *.
- Merge the server blocks. Keep one block per name and port. If Certbot created a new 443 block, move any custom rules into it and delete the old duplicate.
- Keep names unique per port. Each name may appear once per listen address. It is fine to have example.com on port 80 (redirect) and on port 443 (site) in separate blocks.
- Test and reload. Run sudo nginx -t. When the warning is gone, reload with sudo systemctl reload nginx.
Find duplicate server_name entries in the loaded config
sudo nginx -T 2>/dev/null | grep -E '^# configuration file|server_name'
ls -la /etc/nginx/sites-enabled/ /etc/nginx/conf.d/ How to stop it happening again
- Keep backups outside sites-enabled and conf.d
- Use symlinks from sites-available instead of copies
- Run nginx -t after every change and read the warnings
- Use one file per site