Nextcloud container + Seperate nginx container as reverse proxy + cloudflare = Connection Timed Out?

I’m trying to setup nextcloud for my home network, and I’ve been running everything through docker-compose.
Everything worked fine in the beginning, but once I clicked “install”, the entire website broke

I’ve drawn a diagram of what the network looks like currently, I’m not the best at explaining with words.


Basically, I have two NGINX instances, one acting as a reverse proxy (this handles all my requests – I’ve been using this for a while and everything seems to work fine) and the NextCloud container which also hosts its own NGINX instance.

The request seems to be getting stuck on the return trip, because the the Nextcloud NGINX instance seems to be getting the request some of the times, but it doesn’t return anything. The reverse proxy (the one first contacted by Cloudflare) seems to be working fine, because it works with all my other servers fine. Has anyone else had issues like this, and if so how would I resolve them.

Files:
docker-compose.yml

version: "3"

services:
  nginx:
    image: nginx:1.23.2
    volumes:
      - ./service/nginx/conf.d:/etc/nginx/conf.d
      - ./service/nginx/certs:/service/certs
    ports:
      - 80:80
      - 443:443
      - 8080:8080
    restart: always

[...wordpress]

  nextcloud:
    image: nextcloud
    restart: always
    links:
      - nextcloud_db
    volumes:
      - nextcloud:/var/www/html
    environment:
      - MYSQL_PASSWORD=a5e78d0fdd509bc24381e1931358b997
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_HOST=nextcloud_db

  nextcloud_db:
    image: mariadb:10.5
    restart: always
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    volumes:
      - next_db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=bb8a287fc3d7546fc13a1fd8b6a99fba25a081c8
      - MYSQL_PASSWORD=a5e78d0fdd509bc24381e1931358b997
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud

[...wordpress_db]

volumes:
  [...wordpress stuff]
  next_db:
  nextcloud:

nginx cloud.conf (in the conf.d folder of the MAIN nginx reverse-proxy):

server {
    listen 80;
    server_name cloud.examp.com;
    return 301 https://$server_name$request_uri;
}

server {
    listen 8080;
    server_name cloud.examp.com;
    return 301 https://$server_name$request_uri;
}

server {
    listen              443 ssl;
    server_name         cloud.examp.com;

    location / {
        proxy_pass http://nextcloud:80;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;

        # return 200 'Amongus';
        # add_header Content-Type text/plain;
    }

    # Theese should be automaticaly sent to the container via docker volumes
    ssl_certificate     /service/certs/fullchain.pem;
    ssl_certificate_key /service/certs/privkey.pem;
}

(I doubt this is necessary but ill include it anyways) docker-compose-app.service

# /etc/systemd/system/docker-compose-app.service

[Unit]
Description=Lions Service Host
Requires=docker.service
After=docker.service

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/services/service
ExecStart=/usr/bin/docker compose up -d
ExecStop=/usr/bin/docker compose down
TimeoutStartSec=0

[Install]
WantedBy=multi-user.target