You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Traefik搭配Nextcloud出现Bad Gateway错误的排查求助

Troubleshooting "Bad Gateway" with Nextcloud + Traefik + MariaDB

Let's break down why you're hitting that bad gateway error when accessing your Nextcloud instance through Traefik—there's a critical misconfiguration in your Nextcloud container's port setup:

1. The Core Issue: Wrong Port Target for Nextcloud

You’ve set Traefik to route traffic to port 9000 for your Nextcloud app via the traefik.port=9000 label, but here’s the key problem: Nextcloud’s official image uses port 9000 for PHP-FPM, not a standard HTTP web server. Traefik is a reverse proxy that speaks HTTP, so trying to proxy to a PHP-FPM port will fail every time—this is exactly why you’re seeing the bad gateway error.

The correct HTTP port for Nextcloud’s official image is 80 (this is where the built-in web server listens for requests).

2. Fix the Nextcloud Docker Compose Config

Update your Nextcloud service section to point Traefik to the right port, and optionally add a local port mapping for direct testing without Traefik:

version: '2.1'
volumes:
  nextcloud:
  db:
services:
  db:
    image: mariadb
    volumes:
      - db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=my_root_password
      - MYSQL_PASSWORD=my_password
      - MYSQL_DATABASE=my_database
      - MYSQL_USER=my_user
  app:
    image: nextcloud
    restart: always
    networks:
      - web
      - default
    # Optional: Local port mapping to test Nextcloud directly
    ports:
      - "127.0.0.1:8080:80"
    labels:
      - "traefik.backend=app"
      - "traefik.docker.network=web"
      - "traefik.frontend.rule=Host:my_host"
      - "traefik.enable=true"
      # Change this from 9000 to 80
      - "traefik.port=80"
      - "traefik.default.protocol=http"
networks:
  web:
    external: true

3. Additional Checks to Rule Out Other Problems

  • Network Connectivity: Confirm both the Nextcloud and Traefik containers are attached to the web external network. Verify this with:

    docker network inspect web
    

    Look for both containers listed in the "Containers" section of the output.

  • Traefik ACME File Permissions: Your acme.json file needs strict 600 permissions for Traefik to manage SSL certificates correctly. Run this if you haven’t already:

    chmod 600 /opt/traefik/acme.json
    
  • Check Logs for Clues: If issues persist, dig into the container logs to spot other errors (like database connection problems):

    # Nextcloud service logs
    docker-compose logs app
    # Traefik service logs
    cd /path/to/your/traefik-compose-folder
    docker-compose logs traefik
    

4. Restart Services to Apply Changes

After updating the configs, restart both service stacks to make the changes take effect:

# Restart Nextcloud and MariaDB
docker-compose up -d
# Restart Traefik
cd /path/to/your/traefik-compose-folder
docker-compose up -d

Once you’ve made these tweaks, Traefik will correctly proxy HTTP requests to Nextcloud’s web server port, and you should be able to access your instance without the bad gateway error.

内容的提问来源于stack exchange,提问作者Daniel McCrevan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 03:57:22