Fix nginx "conflicting server name ... on 0.0.0.0:80, ignored"
nginx "conflicting server name ... ignored": two server blocks share a name on one address:port and the later is ignored. Find it with nginx -T.
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignoredTwo or more server blocks on the same address and port (0.0.0.0:80) declare server_name example.com. The block read first keeps the name; the name in the later block is ignored. It is only a warning, so nginx -t passes — which is why it often explains "I edited the config and nothing changed". On Ubuntu the usual cause is a backup file left in sites-enabled/.
[1] Read every warning line. You get one per name and address:port, so with listen [::]:80; as well the same name appears twice.
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignorednginx: [warn] conflicting server name "example.com" on [::]:80, ignorednginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successfulDifferent ports do not conflict. The same example.com on 80 and on 8080 passed with no warning.
[2] Check which block actually answers. Here both blocks have example.com, and only the second also has www.example.com:
$ curl -s -H 'Host: example.com' http://127.0.0.1/first$ curl -s -H 'Host: www.example.com' http://127.0.0.1/secondexample.com went to the first block (first); the second block only got the name that did not overlap. If an edit has no effect, you may be editing the ignored block.
[3] Find the file and line for each copy of the name. nginx -T prints every included file and marks each with a # configuration file line.
$ sudo nginx -T 2>/dev/null | grep -nE "^# configuration file|server_name"189:# configuration file /etc/nginx/sites-enabled/default:235: server_name _;272:# server_name example.com;282:# configuration file /etc/nginx/sites-enabled/example.com:285: server_name example.com;289:# configuration file /etc/nginx/sites-enabled/example.com.bak:292: server_name example.com;Line 272 starts with #, so it is a comment and does not count. The conflict is between example.com and example.com.bak.
[4] On Ubuntu, look for copies in sites-enabled/. The packaged nginx.conf reads the two directories differently:
59: include /etc/nginx/conf.d/*.conf;60: include /etc/nginx/sites-enabled/*;conf.d only loads files ending in .conf, but sites-enabled loads every file. A example.com.bak, example.com~ or example.com.orig made before an edit becomes live config.
$ ls -l /etc/nginx/sites-enabled/lrwxrwxrwx 1 root root 34 … default -> /etc/nginx/sites-available/defaultlrwxrwxrwx 1 root root 38 … example.com -> /etc/nginx/sites-available/example.com-rw-r--r-- 1 root root 86 … example.com.bakNormal entries in sites-enabled are symlinks (->) into sites-available. A regular file there is suspect.
[5] Move the copy out of sites-enabled. Moving instead of deleting keeps a way back.
$ sudo mv /etc/nginx/sites-enabled/example.com.bak /root/$ sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successfulOnce the warning is gone, apply it with sudo systemctl reload nginx. To undo, move the file back into sites-enabled/, test and reload.
[6] If the split was intentional, merge it. Typical cases: the same name in both conf.d/ and sites-enabled/, or the same alias (www. and so on) in two site files. Keep the name in one block and remove it from the other block's server_name line. If the goal was a catch-all, do not reuse names — use listen 80 default_server;.
If nginx fails to start because of a long name, see could not build server_names_hash; for port errors see bind() Address already in use.
Analyze your Nginx log in the browser ↗ — nothing is uploaded.