Unable to run NextCloud AIO behind Caddy as reverse proxy, HTTP 502

Hi everyone,
I read similar topics but still have no luck. Trying to run AIO on a VPS powered by Ubuntu 22.04Jammy. Caddy installed from the Caddy repo with the official package manager. Caddy log file is not created for some reason, either.

My Caddyfile:

https://<my.domain>:443 {
    reverse_proxy <my.public.ip.v4>:43195
    log {
        output file /var/log/caddy.log
    }
}

My startup command:

docker run -d --init --sig-proxy=false --name nextcloud-aio-mastercontainer --restart always --publish 8080:8080 --env APACHE_PORT=43195 --env APACHE_IP_BINDING=0.0.0.0 --volume nextcloud_aio_mastercontainer:/mnt/docker-aio-config --volume /var/run/docker.sock:/var/run/docker.sock:ro nextcloud/all-in-one:latest

Output of docker inspect nextcloud-aio-mastercontainer:

[
    {
        "Id": "48140d92758b638ad15f1a8a822cd401903d3e0216eced816abb71a062cac826",
        "Created": "2024-10-01T11:04:05.641362298Z",
        "Path": "/start.sh",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 17016,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2024-10-01T11:04:06.446563332Z",
            "FinishedAt": "0001-01-01T00:00:00Z",
            "Health": {
                "Status": "healthy",
                "FailingStreak": 0,
                "Log": [
                    {
                        "Start": "2024-10-01T11:16:37.986924496Z",
                        "End": "2024-10-01T11:16:38.03297414Z",
                        "ExitCode": 0,
                        "Output": ""
                    },
                    {
                        "Start": "2024-10-01T11:17:08.033967061Z",
                        "End": "2024-10-01T11:17:08.07752751Z",
                        "ExitCode": 0,
                        "Output": ""
                    },
                    {
                        "Start": "2024-10-01T11:17:38.082049687Z",
                        "End": "2024-10-01T11:17:38.127772637Z",
                        "ExitCode": 0,
                        "Output": ""
                    },
                    {
                        "Start": "2024-10-01T11:18:08.132112785Z",
                        "End": "2024-10-01T11:18:08.177873595Z",
                        "ExitCode": 0,
                        "Output": ""
                    },
                    {
                        "Start": "2024-10-01T11:18:38.179000081Z",
                        "End": "2024-10-01T11:18:38.226538479Z",
                        "ExitCode": 0,
                        "Output": ""
                    }
                ]
            }
        },
        "Image": "sha256:6fab5d509d6d65c967881fab29be57c4f33e2d12b28eca9587a019af5c9c73c7",
        "ResolvConfPath": "/var/lib/docker/containers/48140d92758b638ad15f1a8a822cd401903d3e0216eced816abb71a062cac826/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/48140d92758b638ad15f1a8a822cd401903d3e0216eced816abb71a062cac826/hostname",
        "HostsPath": "/var/lib/docker/containers/48140d92758b638ad15f1a8a822cd401903d3e0216eced816abb71a062cac826/hosts",
        "LogPath": "/var/lib/docker/containers/48140d92758b638ad15f1a8a822cd401903d3e0216eced816abb71a062cac826/48140d92758b638ad15f1a8a822cd401903d3e0216eced816abb71a062cac826-json.log",
        "Name": "/nextcloud-aio-mastercontainer",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "docker-default",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "nextcloud_aio_mastercontainer:/mnt/docker-aio-config",
                "/var/run/docker.sock:/var/run/docker.sock:ro"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "bridge",
            "PortBindings": {
                "8080/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "8080"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "always",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "ConsoleSize": [
                33,
                133
            ],
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "private",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": [],
            "BlkioDeviceWriteBps": [],
            "BlkioDeviceReadIOps": [],
            "BlkioDeviceWriteIOps": [],
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": null,
            "PidsLimit": null,
            "Ulimits": [],
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware",
                "/sys/devices/virtual/powercap"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ],
            "Init": true
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/77158bdb2478b7131b2a195824ded43399c1b197ec7dc9f92cdf208b5e487e49-init/diff:/var/lib/docker/overlay2/b3248e20c48291101d554ae2aeb28c2dd7ab7c1098c770a9e2ab6efc99013b0b/diff:/var/lib/docker/overlay2/e3723ae3616ea5900a33261da206b795036c437dd6b60889a105dd5bb1424baa/diff:/var/lib/docker/overlay2/3fe082b6bee4f2eb695af25914d37353d9bf4f997754e559a3aa4bda5b204d31/diff:/var/lib/docker/overlay2/2300873fb9b5f9cba6c43002b5a02d9b1afd35adb75650672cb4026d7845f1c0/diff:/var/lib/docker/overlay2/80d42823ea54476ed93a7b4741bb38e6ab0f8823686940624105be7683a5da6c/diff:/var/lib/docker/overlay2/2cba2c8e1e1dbd178fd3d99ae15a76a89a9e5529abac85e9e60b0481f86050b3/diff:/var/lib/docker/overlay2/5abe0530c57e3e8ea24fbe869f5b0c14b6a8795a32fabfc8025bfb5c18ae7559/diff:/var/lib/docker/overlay2/a61f13ce9c20f57a988ebde929f1b739e4a80024040fdb622da3e41e8062d565/diff:/var/lib/docker/overlay2/f7981f9a309130d5d154a6832b4daa2cec53e3258aecb757243713b4deb7d3bc/diff:/var/lib/docker/overlay2/5da192463b6f78a21bff585ddc57a9736be9f146435737afea5fe19cc87435ed/diff:/var/lib/docker/overlay2/7b6f9914c3f03dbd321dbccfc141e911ecd3c966d7fa43973d633aea61a92b71/diff:/var/lib/docker/overlay2/955e42274c1ccb3873bed0389e45c9e860998c4877efac2d98682c8bcf60de09/diff:/var/lib/docker/overlay2/0faea13441d82ed48b9fb8b0a8b7e76282a12b85d2f9ac3d930530708f5dbe0e/diff:/var/lib/docker/overlay2/28e8e5a7bd4c1c2b25fb6d36e667fffe952ffdb813bfb8897f9fee854e17c225/diff:/var/lib/docker/overlay2/87ec2719413eeda206bddb13cdde0d09b1c0b77794ad4a0596621d947482b55c/diff:/var/lib/docker/overlay2/d0dd3b3f18dde83a3f6baac86fab3c78bfb156a66c6db8390b5687cb8bb7048f/diff:/var/lib/docker/overlay2/84d0a60bc2428d43f0b7933cbf74153f7dc47a1511de4c37da51de96e7148f68/diff:/var/lib/docker/overlay2/1e76ba975162d4ba36d5d1774c71c13ce18a13d1bff93be7e289d7c71389c9e5/diff",
                "MergedDir": "/var/lib/docker/overlay2/77158bdb2478b7131b2a195824ded43399c1b197ec7dc9f92cdf208b5e487e49/merged",
                "UpperDir": "/var/lib/docker/overlay2/77158bdb2478b7131b2a195824ded43399c1b197ec7dc9f92cdf208b5e487e49/diff",
                "WorkDir": "/var/lib/docker/overlay2/77158bdb2478b7131b2a195824ded43399c1b197ec7dc9f92cdf208b5e487e49/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "volume",
                "Name": "nextcloud_aio_mastercontainer",
                "Source": "/var/lib/docker/volumes/nextcloud_aio_mastercontainer/_data",
                "Destination": "/mnt/docker-aio-config",
                "Driver": "local",
                "Mode": "z",
                "RW": true,
                "Propagation": ""
            },
            {
                "Type": "bind",
                "Source": "/var/run/docker.sock",
                "Destination": "/var/run/docker.sock",
                "Mode": "ro",
                "RW": false,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "48140d92758b",
            "Domainname": "",
            "User": "root",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {},
                "8080/tcp": {},
                "8443/tcp": {},
                "9000/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "APACHE_PORT=43195",
                "APACHE_IP_BINDING=0.0.0.0",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "PHPIZE_DEPS=autoconf \t\tdpkg-dev dpkg \t\tfile \t\tg++ \t\tgcc \t\tlibc-dev \t\tmake \t\tpkgconf \t\tre2c",
                "PHP_INI_DIR=/usr/local/etc/php",
                "PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64",
                "PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64",
                "PHP_LDFLAGS=-Wl,-O1 -pie",
                "GPG_KEYS=1198C0117593497A5EC5C199286AF1F9897469DC C28D937575603EB4ABB725861C0779DC5C0A9DE4 AFD8691FDAEDF03BDF6E460563F15A9B715376CA",
                "PHP_VERSION=8.3.11",
                "PHP_URL=https://www.php.net/distributions/php-8.3.11.tar.xz",
                "PHP_ASC_URL=https://www.php.net/distributions/php-8.3.11.tar.xz.asc",
                "PHP_SHA256=b862b098a08ab9bf4b36ed12c7d0d9f65353656b36fb0e3c5344093aceb35802"
            ],
            "Cmd": null,
            "Healthcheck": {
                "Test": [
                    "CMD-SHELL",
                    "/healthcheck.sh"
                ]
            },
            "Image": "nextcloud/all-in-one:latest",
            "Volumes": null,
            "WorkingDir": "/var/www/docker-aio",
            "Entrypoint": [
                "/start.sh"
            ],
            "OnBuild": null,
            "Labels": {},
            "StopSignal": "SIGQUIT"
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "c5c92398de7941b6ac223f95d9b2505dec075e9724db5fedd08b83832de97fef",
            "SandboxKey": "/var/run/docker/netns/c5c92398de79",
            "Ports": {
                "80/tcp": null,
                "8080/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "8080"
                    },
                    {
                        "HostIp": "::",
                        "HostPort": "8080"
                    }
                ],
                "8443/tcp": null,
                "9000/tcp": null
            },
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "14061979ad277b37e43d433aa3cefe5832daec258c395e39b9c37457e172e07c",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null,
                    "NetworkID": "bcb0c4023d07361b28d9badbe4866a7db58858018fa619dda8b6dccc26c6f1ef",
                    "EndpointID": "14061979ad277b37e43d433aa3cefe5832daec258c395e39b9c37457e172e07c",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "DNSNames": null
                }
            }
        }
    }
]

Thanks!

Hi, can you follow https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md#6-how-to-debug-things?

I’m not super handy with Docker containers, but this is a Caddyfile that was provided to me by another user and it works fine on my VM

}

https://nextcloud.domain.com {
header Strict-Transport-Security max-age=31536000;
reverse_proxy 192.x.x.x:443 {
transport http {
tls
tls_insecure_skip_verify
}