Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

nginx warns that a conflicting server name was ignored

Errornginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignored

Short answer

nginx found the same server_name twice for the same address and port, so it keeps the first block and ignores the second one. It is a warning, but the ignored block never serves traffic. Dump the full config with nginx -T, find the duplicate name, then delete the copy or give each block its own name.

  • Applies to nginx 1.26 and 1.28, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print every loaded config file and search for the name in the warning. Two hits for the same listen port are the conflict.

    sudo nginx -T 2>/dev/null | grep -n "server_name\|^# configuration file"
  2. 2Match what you see, then jump to its fix

    1. 1The name in the warning appears in two server_name lines with the same listen portTwo server blocks use the same name on the same portFix
    2. 2-T shows the same file header (# configuration file ...) two timesAn include mask loads the same file twiceFix
    3. 3conflicting server name "" on 0.0.0.0:80, ignoredSeveral blocks have no server_name at allFix

What does the error look like?

  • nginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignored
  • nginx: [warn] conflicting server name "" on 0.0.0.0:80, ignored

Cause 1 of 3

Two server blocks use the same name on the same port

1Check

nginx stores names per address and port. A repeated name on that pair cannot be added, so the later block loses it. Find both blocks and the files they sit in.

sudo nginx -T 2>/dev/null | grep -n "example.com"

2Fix

Remove the old duplicate (often a leftover copy of the site), or change the name in one block. Use a separate block only when the name or the port really differs.

server {
    listen 80;
    server_name example.com www.example.com;
    # one block per name and port
}

3Verify

The test prints no warn line.

sudo nginx -t

Confirmed by nginx.org

Did this fix it?

Cause 2 of 3

An include mask loads the same file twice

1Check

include accepts a mask, so two masks that both match a site file load it twice. Typical case: both conf.d/*.conf and sites-enabled/* pick up one file, or a symlink and its target are both matched.

sudo nginx -T 2>/dev/null | grep -n "^# configuration file"
grep -rn "include" /etc/nginx/nginx.conf

2Fix

Keep each site file under one included folder, or narrow the masks so they no longer overlap.

# in the http block, one mask per folder
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

3Verify

Run the test again; each file now appears once in the dump.

sudo nginx -t && sudo nginx -T 2>/dev/null | grep -c "^# configuration file"

Confirmed by nginx.org

Did this fix it?

Cause 3 of 3

Several blocks have no server_name at all

1Check

A server block without server_name uses the empty name. Two such blocks on one port clash on that empty name.

sudo nginx -T 2>/dev/null | grep -n "listen 80\|server_name"

2Fix

Give every block a real server_name, and mark exactly one block per port as the fallback with default_server in its listen line.

server {
    listen 80 default_server;
    server_name _;
    # fallback for unknown hostnames
}

3Verify

No warn line is printed by the test.

sudo nginx -t

Confirmed by nginx.org

Did this fix it?

How do I stop it coming back?

  • Run nginx -t after every change and read the warn lines, not only the final 'successful'.
  • Keep one file per site, named after the domain, and delete the old copy when a site moves.
  • Use sites-enabled symlinks or conf.d, not both for the same file.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.