502 Bad Gateway Cloudflare Tunnel

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 20.0.5): Nextcloud AIO v7.0.0
Operating system and version (eg, Ubuntu 20.04): Ubuntu 22.04.3 LTS
Apache or nginx version (eg, Apache 2.4.25): Cloudflare Tunnel
PHP version (eg, 7.4): N/A

Hello everyone, I am trying to set up NextCloud AIO and I keep getting a 502 Bad Gateway error when the containers are running. I am trying to run it through Cloudflare Tunnel that is set up in the same server.

I followed the steps here https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md

I also tried this troubleshooting Protecting NextCloud behind CloudFlare Firewall and Anti-DDoS - Autoize

My Tunnel is set for http s://host.ip:11000 with NoTLS Verify enabled.

This is the command that I ran:

sudo docker run -d \
--init \
--sig-proxy=false \
--name nextcloud-aio-mastercontainer \
--restart always \
--publish 8080:8080 \
--env APACHE_PORT=11000 \
--env APACHE_IP_BINDING=127.0.0.1 \
--env SKIP_DOMAIN_VALIDATION=true \
--env NEXTCLOUD_DATADIR="/home/USER/nextcloud/data" \
--volume nextcloud_aio_mastercontainer:/mnt/docker-aio-config \
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
nextcloud/all-in-one:latest

Apache Log:

Waiting for Nextcloud to start...
{"level":"info","ts":1694310098.1244006,"msg":"using provided configuration","config_file":"/tmp/Caddyfile","config_adapter":""}
[Sat Sep 09 21:41:38.128184 2023] [mpm_event:notice] [pid 65:tid 140425457232712] AH00489: Apache/2.4.57 (Unix) configured -- resuming normal operations
[Sat Sep 09 21:41:38.129065 2023] [core:notice] [pid 65:tid 140425457232712] AH00094: Command line: '/usr/local/apache2/bin/httpd -D FOREGROUND'

Database Log:

Setting max connections...
chmod: /var/run/postgresql: Operation not permitted

PostgreSQL Database directory appears to contain a database; Skipping initialization

2023-09-09 21:40:28.760 EDT [15] LOG:  starting PostgreSQL 15.3 on x86_64-pc-linux-musl, compiled by gcc (Alpine 12.2.1_git20220924-r10) 12.2.1 20220924, 64-bit
2023-09-09 21:40:28.760 EDT [15] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2023-09-09 21:40:28.760 EDT [15] LOG:  listening on IPv6 address "::", port 5432
2023-09-09 21:40:28.762 EDT [15] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-09-09 21:40:28.768 EDT [25] LOG:  database system was shut down at 2023-09-09 21:39:44 EDT
2023-09-09 21:40:28.780 EDT [15] LOG:  database system is ready to accept connections

Nextcloud Log:

[09-Sep-2023 21:41:32] NOTICE: fpm is running, pid 427
[09-Sep-2023 21:41:32] NOTICE: ready to handle connections
Activating collabora config...
Failed to activate any config changes
Server error: 'GET https: //hostname.com/hosting/discovery' resulted in a '502 Bad Gateway' response:
502 Bad Gateway
Unable to reach the origin service. The service may be down or it may not be responding to traffic from  (truncated...)

Collabora Logs:

Ready to accept connections on port 9980.

wsd-00001-00019 2023-09-09 21:40:44.947625 -0400 [ remotefontconfig_poll ] ERR  Remote config server has response status code: 502 (Bad Gateway)| wsd/COOLWSD.cpp:1188

Any help would be appreciated it, and if you need more info please ask. Thank you in advance!

Did you already try http://host.ip:11000 ?

Hello, I have tried that and I get ERR_CONNECTION_FAILED.

Edit: Also, the VM has 8GB RAM and it’s using it all, is that normal? Nextcloud is the only thing running on it in a Docker Container.

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

1 Like

Hello, thank you for that link. It helped me realized what I was doing wrong, so it took me a bit of troubleshooting to figure everything out. I’m going to write the steps for future users that might be having the same issues.

  1. On your Cloudflare Tunnel, make sure you set your Public Hostname to HTTP because HTTPS with NoVerify does not work.

  2. Since I am running my Cloudflare Tunnel within a Docker Container, even though it is in the same server, I guess it’s still considered separate, so in my config file, I set Apache to the server’s private IP, instead of 127.0.0.0, my guess is that if you run docker natively on the server you can get away with using 127.0.0.0.

  3. I was trying to map the NEXTCLOUD_DATADIR to /home/MY_USER/nextcloud/data, and I guess it was not liking that, so I changed it to /mnt/nextcloud/data.

After doing this changes it works fine, so this is the final config that I used:

sudo docker run -d \
--init \
--sig-proxy=false \
--name nextcloud-aio-mastercontainer \
--restart always \
--publish 8080:8080 \
--env APACHE_PORT=11000 \
--env APACHE_IP_BINDING='Server Private IP' \
--env SKIP_DOMAIN_VALIDATION=true \
--env NEXTCLOUD_DATADIR="/mnt/nextcloud/data/" \
--volume nextcloud_aio_mastercontainer:/mnt/docker-aio-config \
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
nextcloud/all-in-one:latest

Thank you for your help!

1 Like

Reviving this after a bit of time. I am having the same issues and I am trying to understand the solution here. @Misinthe when you say

I set Apache to the server’s private IP

does that mean that you entered the IP address of the cloudflare tunnel container ?