Nextcloud AIO Caddy and Nginx Proxy Manager - 502 Bad Gateway

The Basics

  • Nextcloud Server version (e.g., 29.x.x):
    • Nextcloud AIO v10.13.0 - Docker Compose, OpenMediaVault
  • Operating system and version (e.g., Ubuntu 24.04):
    • Rasspberry Pi OS - Debian GNU/Linux 12 (bookworm)
  • Web server and version (e.g, Apache 2.4.25):
    • integrated
  • Reverse proxy and version _(e.g. nginx 1.27.2)
    • Caddy (macvlan)
  • Installation method (e.g. AlO, NCP, Bare Metal/Archive, etc.)
    • Nextcloud AIO - Docker - Compose
  • Are you using CloudfIare, mod_security, or similar? (Yes / No)
    • No

I am quite embarased that I have to ask this here.
I am trying to solve this for two days now. I have read a lot of threads and posts here and tried the suggestions and Nextcloud AIO Reverse Proxy + Debugging.

For simplicity and my first try I installed the Linuxserver community images for Nextcloud and MariaDB, configured the Nginx Proxy Manager and everything worked perfectly fine. But I would like to use the official Nextcloud AIO image. I have disabled Nginx PM (docker down) and installed Caddy just out of curiosity and also Caddy works perfectly fine with my Linuxserver configuration.

Both Nginx PM and Caddy get their own client IP addresses via a macvlan configuration. The configured macvlan is in the same network as the server, just for different client IP addresses per container when needed to prevent port overlapps.

Example:
OMV server (with docker): 192.168.178.90
Nginx PM: 192.168.178.35
Caddy: 192.168.178.36

I disabled the Linuxserver community images (docker down) and installed Nextcloud AIO via docker compose on OMV. To keep things simple I did not use macvlan for the Nextcloud AIO container.

I have access to the Nextcloud AIO web-UI (192.168.178.90:8080) and logged in using the passphrase.

The domain check fails.
If I access the server with 192.168.178.90:11000 I get the test code for the domain check.
If I accesss the configured domain I get “502 bad gateway”.

I disabled Nextcloud AIO (docker down), enabled Linuxserver Nextcloud image, changed the IP address in the Caddyfile and everything was working again.

I have no idea what to try next. Please help. I could stay with the simple Linuxserver images but I would like to use the official Nextcloud AIO image if possible.

My Nextcloud AIO Docker Compose File:

services:
  nextcloud-aio-mastercontainer:
    hostname: nextcloud-aio
    image: ghcr.io/nextcloud-releases/all-in-one:latest
    init: true
    #restart: always
    restart: unless-stopped
    container_name: nextcloud-aio-mastercontainer # This line is not allowed to be changed as otherwise AIO will not work correctly
    volumes:
      - nextcloud_aio_mastercontainer:/mnt/docker-aio-config # This line is not allowed to be changed as otherwise the built-in backup solution will not work
      - /var/run/docker.sock:/var/run/docker.sock:ro # May be changed on macOS, Windows or docker rootless. See the applicable documentation. If adjusting, don't forget to also set 'WATCHTOWER_DOCKER_SOCKET_PATH'!
    network_mode: bridge # add to the same network as docker run would do
    ports:
      #- 80:80 # Can be removed when running behind a web server or reverse proxy (like Apache, Nginx, Caddy, Cloudflare Tunnel and else). See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
      - 8080:8080
      #- 8443:8443 # Can be removed when running behind a web server or reverse proxy (like Apache, Nginx, Caddy, Cloudflare Tunnel and else). See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
    environment: # Is needed when using any of the options below
      # AIO_DISABLE_BACKUP_SECTION: false # Setting this to true allows to hide the backup section in the AIO interface. See https://github.com/nextcloud/all-in-one#how-to-disable-the-backup-section
      # AIO_COMMUNITY_CONTAINERS: # With this variable, you can add community containers very easily. See https://github.com/nextcloud/all-in-one/tree/main/community-containers#community-containers
      # APACHE_PORT: 11000 # Is needed when running behind a web server or reverse proxy (like Apache, Nginx, Caddy, Cloudflare Tunnel and else). See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
      APACHE_PORT: 11000 # Is needed when running behind a web server or reverse proxy (like Apache, Nginx, Caddy, Cloudflare Tunnel and else). See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
      # APACHE_IP_BINDING: 127.0.0.1 # Should be set when running behind a web server or reverse proxy (like Apache, Nginx, Caddy, Cloudflare Tunnel and else) that is running on the same host. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
      APACHE_IP_BINDING: 0.0.0.0 # Should be set when running behind a web server or reverse proxy (like Apache, Nginx, Caddy, Cloudflare Tunnel and else) that is running on the same host. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
      # APACHE_ADDITIONAL_NETWORK: frontend_net # (Optional) Connect the apache container to an additional docker network. Needed when behind a web server or reverse proxy (like Apache, Nginx, Caddy, Cloudflare Tunnel and else) running in a different docker network on same server. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
      # BORG_RETENTION_POLICY: --keep-within=7d --keep-weekly=4 --keep-monthly=6 # Allows to adjust borgs retention policy. See https://github.com/nextcloud/all-in-one#how-to-adjust-borgs-retention-policy
      # COLLABORA_SECCOMP_DISABLED: false # Setting this to true allows to disable Collabora's Seccomp feature. See https://github.com/nextcloud/all-in-one#how-to-disable-collaboras-seccomp-feature
      # FULLTEXTSEARCH_JAVA_OPTIONS: "-Xms1024M -Xmx1024M" # Allows to adjust the fulltextsearch java options. See https://github.com/nextcloud/all-in-one#how-to-adjust-the-fulltextsearch-java-options
      # NEXTCLOUD_DATADIR: /mnt/ncdata # Allows to set the host directory for Nextcloud's datadir. ⚠️⚠️⚠️ Warning: do not set or adjust this value after the initial Nextcloud installation is done! See https://github.com/nextcloud/all-in-one#how-to-change-the-default-location-of-nextclouds-datadir
      NEXTCLOUD_DATADIR: ${APPDATA}/nextcloud-aio/data # Allows to set the host directory for Nextcloud's datadir. ⚠️⚠️⚠️ Warning: do not set or adjust this value after the initial Nextcloud installation is done! See https://github.com/nextcloud/all-in-one#how-to-change-the-default-location-of-nextclouds-datadir
      # NEXTCLOUD_MOUNT: /mnt/ # Allows the Nextcloud container to access the chosen directory on the host. See https://github.com/nextcloud/all-in-one#how-to-allow-the-nextcloud-container-to-access-directories-on-the-host
      # NEXTCLOUD_UPLOAD_LIMIT: 16G # Can be adjusted if you need more. See https://github.com/nextcloud/all-in-one#how-to-adjust-the-upload-limit-for-nextcloud
      # NEXTCLOUD_MAX_TIME: 3600 # Can be adjusted if you need more. See https://github.com/nextcloud/all-in-one#how-to-adjust-the-max-execution-time-for-nextcloud
      # NEXTCLOUD_MEMORY_LIMIT: 512M # Can be adjusted if you need more. See https://github.com/nextcloud/all-in-one#how-to-adjust-the-php-memory-limit-for-nextcloud
      # NEXTCLOUD_TRUSTED_CACERTS_DIR: /path/to/my/cacerts # CA certificates in this directory will be trusted by the OS of the nextcloud container (Useful e.g. for LDAPS) See https://github.com/nextcloud/all-in-one#how-to-trust-user-defined-certification-authorities-ca
      # NEXTCLOUD_STARTUP_APPS: deck twofactor_totp tasks calendar contacts notes # Allows to modify the Nextcloud apps that are installed on starting AIO the first time. See https://github.com/nextcloud/all-in-one#how-to-change-the-nextcloud-apps-that-are-installed-on-the-first-startup
      # NEXTCLOUD_ADDITIONAL_APKS: imagemagick # This allows to add additional packages to the Nextcloud container permanently. Default is imagemagick but can be overwritten by modifying this value. See https://github.com/nextcloud/all-in-one#how-to-add-os-packages-permanently-to-the-nextcloud-container
      # NEXTCLOUD_ADDITIONAL_PHP_EXTENSIONS: imagick # This allows to add additional php extensions to the Nextcloud container permanently. Default is imagick but can be overwritten by modifying this value. See https://github.com/nextcloud/all-in-one#how-to-add-php-extensions-permanently-to-the-nextcloud-container
      # NEXTCLOUD_ENABLE_DRI_DEVICE: true # This allows to enable the /dev/dri device for containers that profit from it. ⚠️⚠️⚠️ Warning: this only works if the '/dev/dri' device is present on the host! If it should not exist on your host, don't set this to true as otherwise the Nextcloud container will fail to start! See https://github.com/nextcloud/all-in-one#how-to-enable-hardware-acceleration-for-nextcloud
      # NEXTCLOUD_ENABLE_NVIDIA_GPU: true # This allows to enable the NVIDIA runtime and GPU access for containers that profit from it. ⚠️⚠️⚠️ Warning: this only works if an NVIDIA gpu is installed on the server. See https://github.com/nextcloud/all-in-one#how-to-enable-hardware-acceleration-for-nextcloud.
      # NEXTCLOUD_KEEP_DISABLED_APPS: false # Setting this to true will keep Nextcloud apps that are disabled in the AIO interface and not uninstall them if they should be installed. See https://github.com/nextcloud/all-in-one#how-to-keep-disabled-apps
      # SKIP_DOMAIN_VALIDATION: false # This should only be set to true if things are correctly configured. See https://github.com/nextcloud/all-in-one?tab=readme-ov-file#how-to-skip-the-domain-validation
      # TALK_PORT: 3478 # This allows to adjust the port that the talk container is using which is exposed on the host. See https://github.com/nextcloud/all-in-one#how-to-adjust-the-talk-port
      # WATCHTOWER_DOCKER_SOCKET_PATH: /var/run/docker.sock # Needs to be specified if the docker socket on the host is not located in the default '/var/run/docker.sock'. Otherwise mastercontainer updates will fail. For macos it needs to be '/var/run/docker.sock'
    # security_opt: ["label:disable"] # Is needed when using SELinux

#   # Optional: Caddy reverse proxy. See https://github.com/nextcloud/all-in-one/discussions/575
#   # Alternatively, use Tailscale if you don't have a domain yet. See https://github.com/nextcloud/all-in-one/discussions/5439
#   # Hint: You need to uncomment APACHE_PORT: 11000 above, adjust cloud.example.com to your domain and uncomment the necessary docker volumes at the bottom of this file in order to make it work
#   # You can find further examples here: https://github.com/nextcloud/all-in-one/discussions/588
#   caddy:
#     image: caddy:alpine
#     restart: always
#     container_name: caddy
#     volumes:
#       - caddy_certs:/certs
#       - caddy_config:/config
#       - caddy_data:/data
#       - caddy_sites:/srv
#     network_mode: "host"
#     configs:
#       - source: Caddyfile
#         target: /etc/caddy/Caddyfile
# configs:
#   Caddyfile:
#     content: |
#       # Adjust cloud.example.com to your domain below
#       https://cloud.example.com:443 {
#         reverse_proxy localhost:11000
#       }

volumes: # If you want to store the data on a different drive, see https://github.com/nextcloud/all-in-one#how-to-store-the-filesinstallation-on-a-separate-drive
  nextcloud_aio_mastercontainer:
    name: nextcloud_aio_mastercontainer # This line is not allowed to be changed as otherwise the built-in backup solution will not work
  # caddy_certs:
  # caddy_config:
  # caddy_data:
  # caddy_sites:

Caddy Docker Compose File:

services:
  caddy:
    image: caddy:latest
    restart: unless-stopped

    networks:
      caddy-network:
        ipv4_address: 192.168.178.36    # Change, your caddy ip-address (macvlan)
        mac_address: xx:xx:xx:xx:xx:xx  # fixed mac address for router port forwarding

    ports:
      - "80:80"
      - "443:443"
      # - "443:443/udp"

    volumes:
      - ${APPDATA}/caddy/Caddyfile:/etc/caddy/Caddyfile
      # - ./site:/srv
      - ${APPDATA}/caddy/data:/data
      - ${APPDATA}/caddy/config:/config
  
networks:
  caddy-network:
    name: macvlan       # network name of your macvlan network
    external: true

Caddyfile:

# global setting for all websites
{
        email name@maildomain.net
}

https://my.domain.net:443 {
#       redir /.well-known/carddav /remote.php/dav/ 301
#       redir /.well-known/caldav /remote.php/dav/ 301

#       header Strict-Transport-Security max-age=31536000;
        reverse_proxy 192.168.178.90:11000 {
#               transport http {
#                       tls
#                       tls_insecure_skip_verify
#               }
        }
}

Maybe too much text: Please help!

I have tested with Caddy (macvlan) and Nginx PM (macvlan).
Only one at a time, of course, and router port forwarding configuration accordingly.

What works:

Nextcloud AIO:
host-ip(192.168.178.90):8080 → nextcloud-aio-mastercontainer → web UI login
host-ip(192.168.178.90):11000 → aio-domaincheck → returns check hash code

Linuxserver Nextcloud + MariaDB (macvlan):
dyndns-domain → Caddy (192.168.178.36) or Nginx PM (192.168.178.35) → Linuxserver Nextcloud + MariaDB (192.168.178.40)

So my dyndns configuration at my provider and within my router works.
Router, opened/forwarded ports:
TCP 443 + TCP 80 → Caddy or Nginx PM

What does not work:

Nextcloud AIO:
dyndns-domain → Caddy or NginxPM → host-ip(192.168.178.90):11000
Domain check fails - 502 Bad Gateway

I have tested and tried everything I could find.
There must be a stupid mistake or misunderstanding on my side.

Maybe there is a problem with IPv6 or something else?
IPv6 is not enabled in my docker configuration.

I would really like to use the official Nextcloud AIO image.

Thanks.

I believe at least part of your situation is described under item 3’s On the same server in a Docker container of the AIO Reverse Proxy Configuration document.

Your independent RP is associated with its own network in Docker, so you need to decide how to tie things together. Three approaches are described when expanding the On the same server in Docker container section.

2 Likes

Oh my god! As I said, a stupid mistake and lack of docker knowledge on my side.
I have read this part of the documentation several times but I did not understand it!
Your hint put me in the right direction.

All the other containers and the Caddy are in the same macvlan network, so it works.
Nextcloud AIO has its own network “nextcloud-aio”. So, connecting the Caddy container to a secondary network “nextcloud-aio” did the trick.

@jtr thank you so much for taking the time and your valuable hint! I have learned a lot!

Now I know how to do it in the future and also for Nginx PM.

My new Caddy compose file:

services:
  caddy:
    image: caddy:latest
    restart: unless-stopped
    container_name: caddy

    networks:
      caddy-network:
        ipv4_address: 192.168.178.36    # Change, your caddy ip-address (macvlan)
        mac_address: xx:xx:xx:xx:xx:xx  # fixed mac address for router port forwarding
      nextcloud-aio:

    ports:
      - "80:80"
      - "443:443"
      # - "443:443/udp"

    volumes:
      - ${APPDATA}/caddy/Caddyfile:/etc/caddy/Caddyfile
      # - ./site:/srv
      - ${APPDATA}/caddy/data:/data
      - ${APPDATA}/caddy/config:/config
  
networks:
  caddy-network:
    name: macvlan       # network name of your macvlan network
    external: true
  nextcloud-aio:
    external: true

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.