GrepBoard/Manuals
605 manuals ·

Fix nginx: a duplicate default server for 0.0.0.0:80

·Tested on Ubuntu 24.04 · nginx 1.24.0 (Docker) · 2026-10·Test scope ↓·5 steps

nginx -t says a duplicate default server for 0.0.0.0:80? Two listen lines on the same port have default_server. Find the Ubuntu default site and keep only one.

output
2026/10/27 01:01:52 [emerg] 298#298: a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/example.com:2nginx: configuration file /etc/nginx/nginx.conf test failed

Two listen … default_server lines exist for the same address and port (0.0.0.0:80). The file in the message is the second one read; the first is in another file. With the Ubuntu package, the other one is almost always the stock site sites-enabled/default. Remove default_server from one of them or disable the stock site.

default_server is a property of the listen port, not of a server name (nginx docs). It picks the one block per port that answers requests whose Host header matches no server_name, so two of them stop nginx from starting.

[1] Find the other one. Two shortcuts fail here.

console
# grep -Rn default_server /etc/nginx/sites-enabled/ /etc/nginx/conf.d/
output
/etc/nginx/sites-enabled/default:22:	listen 80 default_server;/etc/nginx/sites-enabled/default:23:	listen [::]:80 default_server;/etc/nginx/sites-enabled/default:27:	# listen 443 ssl default_server;/etc/nginx/sites-enabled/default:28:	# listen [::]:443 ssl default_server;/etc/nginx/sites-enabled/example.com:2:    listen 80 default_server;/etc/nginx/sites-enabled/example.com:3:    listen [::]:80 default_server;

Lines 27 and 28 start with #, so they are comments and play no part in the clash. The clash is lines 22-23 of default against lines 2-3 of example.com.

console
# nginx -T 2>/dev/null | wc -l; echo "exit=${PIPESTATUS[0]}"
output
0exit=1

[2] Decide which block should be the default — the one that answers requests no server_name matches (requests by bare IP, unknown domains).

You wantDo
your site answers everythingdisable the stock site → [3]
the stock site (or an empty block returning 444) answers unknown hostsremove default_server from your site → [4]

[3] Disable the stock site. Only the symlink goes away; the original stays in sites-available/default, so this is reversible.

console
# rm /etc/nginx/sites-enabled/default# nginx -t
output
nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful

[4] Or remove default_server from your site — both the IPv4 and IPv6 lines. In the test [::]:80 was duplicated too, but the error only reported the first conflict, 0.0.0.0:80.

/etc/nginx/sites-available/example.com
server {   listen 80;   listen [::]:80;    server_name example.com;    root /var/www/html;}

Once the test passes, nginx -T prints again, so you can see which block is the default for each port.

console
# nginx -T 2>/dev/null | grep -nE '^# configuration file|listen'
output
…189:# configuration file /etc/nginx/sites-enabled/default:211:	listen 80 default_server;212:	listen [::]:80 default_server;…282:# configuration file /etc/nginx/sites-enabled/example.com:284:    listen 80;285:    listen [::]:80;

[5] Port 443 works the same way. If listen 443 ssl default_server; was copied into every HTTPS block, the same error appears for 0.0.0.0:443 (only port 80 was reproduced here). Reload after the test passes.

console
# nginx -t && systemctl reload nginx

Two blocks with the same server_name are only a warning, and one of them is ignored; see conflicting server name ignored.

Analyze your Nginx log in the browser ↗ — nothing is uploaded.

#nginx#default_server#sites-enabled#nginx-t