Skip to content

[Bug]: Nginx WebSocket config snippet produces duplicate location / block #569

Description

@vanyasem

Describe the bug

The "Configure WebSocket Support" instructions tell users to create nginx/vhost.d/<host> containing a location / { ... } block. But the generated server config already emits its own location / { ... } block, and the vhost.d file is included at server scope (not inside the existing location). The result is two sibling location / directives in the same server, which nginx rejects:

nginx: [emerg] duplicate location "/" in /etc/nginx/conf.d/default.conf

This pattern comes from nginx-proxy, which exposes two distinct include points per vhost:

vhost.d/<host> — included at server scope
vhost.d/<host>_location — included inside the generated location / block

The directives in the snippet (proxy_set_header Upgrade, proxy_read_timeout, client_max_body_size) only make sense inside a location block, so they need to go in the _location variant — without their own location { ... } wrapper. The docs currently mix the two conventions: _location-style contents written to a server-scope filename, with an extra location / wrapper on top.

Proposed fix

Update the snippet to:

cat > nginx/vhost.d/teldrive.yourdomain.com_location << 'EOL'
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
client_max_body_size 2000M;
EOL

Two changes: the filename gets the _location suffix, and the wrapping location / { ... } is removed. The directives are then injected into the existing location /, WebSocket upgrades and large uploads work, and no duplicate block is produced.

Reproduction

Follow the WebSocket Support section and create nginx/vhost.d/teldrive.yourdomain.com exactly as documented.
Reload nginx / restart the container.
Inspect the generated server block — as shown in the docs, it contains both include /etc/nginx/vhost.d/teldrive.yourdomain.com; (which injects a location /) and a literal location / { proxy_pass ...; } immediately after.
nginx refuses the config because location / is declared twice in the same server.

Expected behavior

WebSocket directives are merged into the existing location /, nginx reloads cleanly.

Version

1.8.3

Which Platform are you using?

Linux

Additional context

Offending nginx/conf.d/default.conf snippet:
Image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions