Can't connect to Nextcloud | Gateway Timeout

Hello everyone, I have decided to use Traefik because using nginx reverse proxy gave me problems. I don't know much about Traefik, but I have tried to make a private cloud for remote access using Nextcloud. The problem is that I get the following error with Nextcloud: Gateway Timeout. But when I want to access to Nginx web server it works fine.

The IPs of my containers in the traefik docker networks are:
traefik: 172.28.0.2
nextcloud: 172.28.0.3

I also used Duckdns for the domain names.

This is the steps and configuration i took:

  1. I open the port 80 and 443 ports in my router.

  2. traefik:

2.1 Executed my traefik docker compose file:

version: '3'

networks:
  traefik:
    external: true

services:
  traefik:
    restart: always
    image: "traefik:latest"
    container_name: "traefik"
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080" 
    volumes:
      - /traefik/etc:/etc/traefik
      - /traefik/certs:/etc/traefik/certs/
      - /traefik/logs:/var/log/traefik
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - traefik

2.2 With my configuration file

global:
  checkNewVersion: true
  sendAnonymousUsage: false 

log:
  level: ERROR 
  format: common 
  filePath: /var/log/traefik/traefik.log

accesslog:
  format: common  
  filePath: /var/log/traefik/access.log

api:
 dashboard: true  
 insecure: true

entryPoints:
  web:
    address: :80
    http:
      redirections:
        entryPoint:
          to: websecure
          scheme: https

  websecure:
    address: :443

certificatesResolvers:
  staging:
    acme:
      email: rmendezh@ies-sabadell.cat
      storage: /etc/traefik/certs/acme.json
      caServer: "https://acme-staging-v02.api.letsencrypt.org/directory"
      httpChallenge:
        entryPoint: web
  production:
    acme:
      email: rmendezh@ies-sabadell.cat
      storage: /etc/traefik/certs/acme.json
      caServer: "https://acme-v02.api.letsencrypt.org/directory"
      httpChallenge:
        entryPoint: web

providers:
  docker:
    exposedByDefault: false 
  file:
    directory: /etc/traefik
    watch: true
  1. My compsoe file for nextcloud
version: '3.2'

networks:
  traefik:
    external: true
  backend:
    external: true

services:

  db:
    image: mariadb:10.5
    restart: always
    container_name: db
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    volumes:
      - /nextcloud/database:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=*******
      - MYSQL_PASSWORD=*******
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    networks:
      - backend

  nextcloud:
    container_name: nextcloud
    networks:
      - traefik
      - backend
    depends_on:
      - db
    ports:
      - 8282:80
    image: nextcloud:apache
    restart: always
    volumes:
      - /nextcloud/html:/var/www/html
      - /nextcloud/logs:/var/log
    environment:
      - MYSQL_PASSWORD=*******
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_HOST=db
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.nextcloud.entrypoints=web, websecure"
      - "traefik.http.routers.nextcloud.rule=Host(`my.domain.com`)"
      - "traefik.http.routers.nextcloud.tls=true"
      - "traefik.http.routers.nextcloud.tls.certresolver=production"
  1. I edited the config.php file in Nextcloud. I addded:
  'trusted_domains' =>
  array (
    0 => '192.168.1.13:8282',
    1 => 'my.domain.org',
  ),
  'trusted_proxies' =>
  array (
    0 => '172.28.0.2',
  ),

Screenshot from the service of traefik:

If you have a problem, I recommend to set the Traefik log level to DEBUG, not to ERROR, and have a look at it. Furthermore check your dashboard at http://IP:8080/dashboard/.

You can add the right loadbalancer.server.port for your nextcloud container, see docs.

You open a port in your nextcloud container - that is not necessary. Traefik and nextcloud share the same Docker network and can reach each other. With that you don't need your trusted setup, because only containers in your Docker network can reach nextcloud.

You use web as entrypoint on your nextcloud container - that is not necessary. You have a redirect from web to websecure set up and I am not sure if the , in between might be a problem.

Also try adding providers.docker.network=traefik to your Traefik static configuration. Just had the same issue trying to run portainer. Even though Traefik is not part of the portainer network, it still took a portainer network IP as target, which it could not reach.

Hello! Thanks for your feedback
I put the port 8282 in my nextcloud for use it meanwhile i'm solving the problem.
I decided to edit and put the things you told me.

  1. I edited my treaefik configuration and set the Traefik log level to DEBUG
log:
  level: DEBUG 
  format: common
  filePath: /var/log/traefik/traefik.log
  1. Added providers.docker.network=traefik yo my traefik static configuration dcoker-compose.yml
version: '3'

networks:
  traefik:
    external: true

services:
  traefik:
    restart: always
    image: "traefik:latest"
    container_name: "traefik"
    command: 
       - "--providers.docker.network=traefik"
    ports:
      - "80:80"
      - "443:443"
      # (Optional) Expose Dashboard
      - "8080:8080"  # Don't do this in production!
    volumes:
      - /traefik/etc:/etc/traefik
      - /traefik/certs:/etc/traefik/certs/
      - /traefik/logs:/var/log/traefik
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - traefik

Restart my traefik container and get this error here:

time="2022-11-20T16:48:17Z" level=debug msg="'504 Gateway Timeout' caused by: dial tcp 172.30.0.3:80: i/o timeout"

Hey I solved It by adding in my nextcloud configuration this in /etc/apache2/apache2.conf:

ServerName my.domain.org

Also in /var/www/nextcloud/config/config.php

  'trusted_domains' =>
  array (
    0 => '192.168.1.13:8282',
    1 => 'my.domain.org',
  ),
  'trusted_proxies' =>
  array (
    0 => '172.28.0.0/16',
  ),

and in my traefik docker-compose.yml:

    command:
      - "--providers.docker.network=traefik"

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