0

I'm trying to set up a Nextcloud instance at VPS Server via a Docker image. I found some Docker-Compose on GitHub and tried to build it with my parameters. I registered my domains and checked that they point to my ip at whatsmydns.net. However after following instructions and then trying to access nextcloud from the browser it didn't show up. I ended up finding this in the nginx logs:

20fed8b34657:/app# nginx -t
2024/05/28 10:51:31 [emerg] 76#76: duplicate location "/.well-known/acme-challenge/" in /etc/nginx/vhost.d/default:2
nginx: [emerg] duplicate location "/.well-known/acme-challenge/" in /etc/nginx/vhost.d/default:2
nginx: configuration file /etc/nginx/nginx.conf test failed

which I believe leads to proxy being unable to start because the containers can still be accessed locally with curl:

20fed8b34657:/app# curl -I http://172.21.0.3:9980
HTTP/1.1 200 OK
Date: Tue, 28 May 2024 10:49:10
Server: COOLWSD HTTP Server 24.04.3.1
Content-Length: 2
Content-Type: text/plain
Last-Modified: Tue, 28 May 2024 10:49:10
Connection: close

My docker-compose.yml is the same as in the example on GitHub except that I plugged in my parameters. It is worth to mention that I'm very new to both Docker and Nginx. How should I deal with config file? How to prevent Docker from generating incorrect conf? default.conf below, where I replaced domains for Collabora and Nextcloud with office.example.com and cloud.example.com respectively:

# nginx-proxy version : 1.5.2-48-ge904471
# Networks available to the container running docker-gen (which are assumed to
# match the networks available to the container running nginx):
#     cloud-compose_proxy-tier
# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
# scheme used to connect to this server
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
    default $http_x_forwarded_proto;
    '' $scheme;
}
map $http_x_forwarded_host $proxy_x_forwarded_host {
    default $http_x_forwarded_host;
    '' $host;
}
# If we receive X-Forwarded-Port, pass it through; otherwise, pass along the
# server port the client connected to
map $http_x_forwarded_port $proxy_x_forwarded_port {
    default $http_x_forwarded_port;
    '' $server_port;
}
# Include the port in the Host header sent to the container if it is non-standard
map $server_port $host_port {
    default :$server_port;
    80 '';
    443 '';
}
# If the request from the downstream client has an "Upgrade:" header (set to any
# non-empty value), pass "Connection: upgrade" to the upstream (backend) server.
# Otherwise, the value for the "Connection" header depends on whether the user
# has enabled keepalive to the upstream server.
map $http_upgrade $proxy_connection {
    default upgrade;
    '' $proxy_connection_noupgrade;
}
map $upstream_keepalive $proxy_connection_noupgrade {
    # Preserve nginx's default behavior (send "Connection: close").
    default close;
    # Use an empty string to cancel nginx's default behavior.
    true '';
}
# Abuse the map directive (see <https://stackoverflow.com/q/14433309>) to ensure
# that $upstream_keepalive is always defined.  This is necessary because:
#   - The $proxy_connection variable is indirectly derived from
#     $upstream_keepalive, so $upstream_keepalive must be defined whenever
#     $proxy_connection is resolved.
#   - The $proxy_connection variable is used in a proxy_set_header directive in
#     the http block, so it is always fully resolved for every request -- even
#     those where proxy_pass is not used (e.g., unknown virtual host).
map "" $upstream_keepalive {
    # The value here should not matter because it should always be overridden in
    # a location block (see the "location" template) for all requests where the
    # value actually matters.
    default false;
}
# Apply fix for very long server names
server_names_hash_bucket_size 128;
# Default dhparam
ssl_dhparam /etc/nginx/dhparam/dhparam.pem;
# Set appropriate X-Forwarded-Ssl header based on $proxy_x_forwarded_proto
map $proxy_x_forwarded_proto $proxy_x_forwarded_ssl {
    default off;
    https on;
}
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
log_format vhost escape=default '$host $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$upstream_addr"';
access_log off;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHA                                   CHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305';
    ssl_prefer_server_ciphers off;
error_log /dev/stderr;
# HTTP 1.1 support
proxy_http_version 1.1;
proxy_set_header Host $host$host_port;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $proxy_x_forwarded_host;
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl;
proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;
proxy_set_header X-Original-URI $request_uri;
# Mitigate httpoxy attack (see README for details)
proxy_set_header Proxy "";
server {
    server_name _; # This is just an invalid value which will never trigger on a real hostname.
    server_tokens off;
    http2 on;
    listen 80;
    listen 443 ssl;
    ssl_session_cache shared:SSL:50m;
    ssl_session_tickets off;
    ssl_certificate /etc/nginx/certs/default.crt;
    ssl_certificate_key /etc/nginx/certs/default.key;
    location ^~ / {
        return 503;
    }
}
# cloud.example.com/
upstream cloud.example.com {
    # Container: nextcloud
    #     networks:
    #         cloud-compose_default (unreachable)
    #         cloud-compose_proxy-tier (reachable)
    #     IP address: 172.19.0.5
    #     exposed ports: 80/tcp
    #     default port: 80
    #     using port: 80
    server 172.19.0.5:80;
}
server {
    server_name cloud.example.com;
    http2 on;
    listen 80 ;
    location /.well-known/acme-challenge/ {
        auth_basic off;
        allow all;
        root /usr/share/nginx/html;
        try_files $uri =404;
        break;
    }
    listen 443 ssl ;
    # No certificate found for this vhost, so use the default certificate and
    # return an error code if the user connects via https.
    ssl_certificate /etc/nginx/certs/default.crt;
    ssl_certificate_key /etc/nginx/certs/default.key;
    if ($https) {
        return 500;
    }
    include /etc/nginx/vhost.d/default;
    location / {
        proxy_pass http://cloud.example.com;
        set $upstream_keepalive false;
    }
}
# office.example.com/
upstream office.example.com {
    # Container: collabora
    #     networks:
    #         cloud-compose_proxy-tier (reachable)
    #     IP address: 172.19.0.4
    #     exposed ports: 9980/tcp
    #     default port: 9980
    #     using port: 9980
    #         /!\ WARNING: Virtual port published on host.  Clients
    #                      might be able to bypass nginx-proxy and
    #                      access the container's server directly.
    server 172.19.0.4:9980;
}
server {
    server_name office.example.com;
    http2 on;
    listen 80 ;
    location /.well-known/acme-challenge/ {
        auth_basic off;
        allow all;
        root /usr/share/nginx/html;
        try_files $uri =404;
        break;
    }
    listen 443 ssl ;
    # No certificate found for this vhost, so use the default certificate and
    # return an error code if the user connects via https.
    ssl_certificate /etc/nginx/certs/default.crt;
    ssl_certificate_key /etc/nginx/certs/default.key;
    if ($https) {
        return 500;
    }
    include /etc/nginx/vhost.d/default;
    location / {
        proxy_pass http://office.example.com;
        set $upstream_keepalive false;
    }
}

Any help is appreciated. Thanks!

2 Answers 2

0

We experienced the same issue after a recent update to nginx/nginx-proxy and nginxproxy/acme-companion.

You should remove the following volume from the letsencrypt-companion service in the docker-compose.yml:

    - proxy-vhost.d:/etc/nginx/vhost.d
1
  • I ended up moving on to Nextcloud AIO because didn't figure it out myself. But thanks! Commented May 30 at 11:17
0

In your default config, check the lines include /etc/nginx/vhost.d/default;. My guess is that the config is recurisvely importing itself.

Try removing/commenting out these imports and try again.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .