Fix nginx duplicate upstream
Fix nginx duplicate upstream by finding the second upstream block with the same name, then merging the servers into one block or renaming one group.
2026/11/27 23:28:36 [emerg] 13#13: duplicate upstream "app" in /lab/before.conf:6nginx: [emerg] duplicate upstream "app" in /lab/before.conf:6nginx: configuration file /lab/before.conf test failedTwo upstream blocks inside http have the same name. Even if each block holds valid server entries, nginx stops reading the configuration. Merge the blocks into one, or rename one if they were meant to be different groups.
[1] Open the file and line at the end of the error (before.conf:6). That line is the declaration read later. The earlier one is higher in the same file or in another file pulled in by include. The container ran nginx -t -c /lab/before.conf.
events {}http { upstream app { server 127.0.0.1:18081; } upstream app { server 127.0.0.1:18082; } server { listen 127.0.0.1:18080; location / { proxy_pass http://app; } }}[2] Find the earlier declaration. If the configuration is split across files, search every folder that gets included, such as conf.d/ and sites-enabled/. Names are matched without regard to case, so add -i.
$ grep -RniE '^\s*upstream\s+app\b' /etc/nginx/[3] Names that differ only in letter case count as the same name. Checking upstream app together with upstream App gives this:
$ nginx -t -c /lab/before-case.conf2026/11/27 23:28:36 [emerg] 19#19: duplicate upstream "App" in /lab/before-case.conf:6nginx: [emerg] duplicate upstream "App" in /lab/before-case.conf:6nginx: configuration file /lab/before-case.conf test failedThe name in the error is the spelling of the second declaration (App). Even if proxy_pass http://app; uses the first spelling, that spelling does not appear in the message, so search for both. The nginx 1.28.0 source compares names with a case-insensitive function (ngx_strncasecmp).
[4] Gather the server entries of both blocks into one block. This is the right fix if you meant to spread requests over both backends. If the two blocks belonged to different applications, do not merge them: rename one and change the proxy_pass that uses it.
events {}http { upstream app { server 127.0.0.1:18081; server 127.0.0.1:18082; } server { listen 127.0.0.1:18080; location / { proxy_pass http://app; } }}Putting two backends in one group splits requests between them. If one was meant as a spare, add backup at the end of that server line (server directive).
[5] Check again.
$ nginx -t -c /lab/after.confnginx: the configuration file /lab/after.conf syntax is oknginx: configuration file /lab/after.conf test is successfulThe exit code was 1 before the fix and 0 after. When the check passes, reload the way your deployment does (nginx -s reload) and send requests to confirm both backends answer. nginx -t does not check whether a backend is running.
For the opposite error, a group with no server at all, see Fix nginx no servers are inside upstream. If the check passes but requests return 502, continue with Tell the cause of an Nginx 502 Bad Gateway from error.log.
Analyze your Nginx log in the browser ↗ — nothing is uploaded.