DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk8 min

Nextcloud with Traefik and Docker Compose on a VPS: Deployment Guide

A practical Docker Compose architecture for running Nextcloud behind Traefik on a VPS, including networks, ACME certificates, proxy settings, DAV discovery, and fixes for common errors.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Nextcloud works reliably behind Traefik on a VPS when the containers share the correct Docker networks, Traefik terminates HTTPS, and Nextcloud is explicitly configured to trust the proxy. The deployment below uses Docker Compose, a separate database network, Traefik v3-style labels, and an ACME certificate resolver.

What the finished stack looks like

The public request path is:

Internet → VPS ports 80/443 → Traefik → Nextcloud:80

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Traefik handles the public hostname and TLS certificate. Nextcloud listens on its internal HTTP port because TLS has already been terminated at the proxy. A database container stays on a private Docker network and is not published to the Internet.

Use two Docker networks:

  • proxy: shared by Traefik and Nextcloud so the router can reach the application.
  • internal: shared by Nextcloud and the database, with no host port exposed for the database.

This separation limits accidental exposure and makes the proxy route explicit. If you use a different network name, change the network label and the Compose declarations together.

#1 Best Overall
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
  • Includes Raspberry Pi 5 with 2.4Ghz 64-bit quad-core CPU (8GB RAM)
  • Includes 128GB Micro SD Card pre-loaded with 64-bit Raspberry Pi OS, USB MicroSD Card Reader
  • CanaKit Turbine Black Case for the Raspberry Pi 5
  • CanaKit Low Noise Bearing System Fan
  • Mega Heat Sink - Black Anodized

Prerequisites on the VPS

DNS and hostname

Create an A record for a hostname such as cloud.example.com pointing to the VPS public IPv4 address. Add an AAAA record only when IPv6 is correctly routed and firewalled on the server. The hostname must resolve before ACME validation can succeed.

Firewall and host access

Allow SSH from your administration addresses and allow inbound TCP ports 80 and 443. Do not expose the database port. Port 80 is useful even when the site is intended to be HTTPS-only because ACME HTTP challenges and HTTP-to-HTTPS redirects commonly use it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Docker storage

Install Docker Engine and the Docker Compose plugin using the instructions for your VPS distribution. Create a project directory, keep the Compose file and Traefik configuration there, and place persistent data on durable VPS storage. Back up the Nextcloud data directory, database, and Traefik ACME storage independently.

Prepare Traefik’s certificate storage

Traefik must be able to write its ACME state. From the project directory:

mkdir -p traefik/letsencrypt
 touch traefik/letsencrypt/acme.json
 chmod 600 traefik/letsencrypt/acme.json

The restrictive mode is important because the file can contain private key material. Keep it on persistent storage so a container recreation does not discard certificate state.

Rank #2
CanaKit Raspberry Pi 5 16GB Starter Kit PRO - Turbine Black (128GB Edition) (16GB RAM)
  • Includes Raspberry Pi 5 16GB with 2.4Ghz 64-bit quad-core CPU (16GB RAM)
  • Includes 128GB Micro SD Card pre-loaded with 64-bit Raspberry Pi OS, USB MicroSD Card Reader
  • CanaKit Turbine Black Case for the Raspberry Pi 5
  • CanaKit Low Noise Bearing System Fan
  • Mega Heat Sink - Black Anodized

Static Traefik configuration

The following static configuration enables the Docker provider and a resolver named letsencrypt. The name is case-sensitive; the label and configuration must use exactly the same spelling and capitalization.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
entryPoints:
  web:
    address: :80
  websecure:
    address: :443

providers:
  docker:
    endpoint: unix:///var/run/docker.sock
    exposedByDefault: false

certificatesResolvers:
  letsencrypt:
    acme:
      email: [email protected]
      storage: /letsencrypt/acme.json
      dnsChallenge:
        provider: cloudflare

The DNS challenge provider shown is an example. Configure the credentials required by the DNS provider you actually use, and do not place secrets directly in a publicly readable Compose file. An HTTP challenge can also be used when it better fits your DNS and firewall arrangement.

Traefik v3 uses its current rule syntax. Do not add the deprecated ruleSyntax label; the provider documentation says that label is being removed in a future major version.

Compose file for Nextcloud, a database, and Traefik

This example uses PostgreSQL, but the important proxy details are the networks, labels, and Nextcloud proxy variables. Replace the example domain and secrets before deployment.

services:
  traefik:
    image: traefik:v3
    command:
      - --configFile=/etc/traefik/traefik.yml
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./traefik/traefik.yml:/etc/traefik/traefik.yml:ro
      - ./traefik/letsencrypt:/letsencrypt
    networks:
      - proxy
    restart: unless-stopped

  db:
    image: postgres:16
    environment:
      POSTGRES_DB: nextcloud
      POSTGRES_USER: nextcloud
      POSTGRES_PASSWORD: change-this-long-secret
    volumes:
      - db_data:/var/lib/postgresql/data
    networks:
      - internal
    restart: unless-stopped

  nextcloud:
    image: nextcloud:latest
    depends_on:
      - db
    environment:
      POSTGRES_HOST: db
      POSTGRES_DB: nextcloud
      POSTGRES_USER: nextcloud
      POSTGRES_PASSWORD: change-this-long-secret
      NEXTCLOUD_TRUSTED_DOMAINS: cloud.example.com
      TRUSTED_PROXIES: 172.20.0.0/16
      OVERWRITEPROTOCOL: https
      OVERWRITEHOST: cloud.example.com
    volumes:
      - nextcloud_data:/var/www/html
    networks:
      - proxy
      - internal
    labels:
      - traefik.enable=true
      - traefik.docker.network=proxy
      - traefik.http.routers.nextcloud.rule=Host(`cloud.example.com`)
      - traefik.http.routers.nextcloud.entrypoints=websecure
      - traefik.http.routers.nextcloud.tls=true
      - traefik.http.routers.nextcloud.tls.certresolver=letsencrypt
      - traefik.http.services.nextcloud.loadbalancer.server.port=80
    restart: unless-stopped

volumes:
  db_data:
  nextcloud_data:

networks:
  proxy:
    name: proxy
  internal:
    name: nextcloud-internal

Use a pinned, tested image tag rather than latest for a production change-controlled environment. The example leaves the tag visible so you can select the Nextcloud edition and version appropriate for your maintenance policy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
CanaKit Raspberry Pi 5 Essentials Starter Kit (4GB RAM)
  • CanaKit Raspberry Pi 5 Essentials Starter Kit

The loadbalancer.server.port=80 label tells Traefik which port to use inside the Nextcloud container. It is not a host port mapping and should not be changed to 443 merely because the public site uses HTTPS.

Configure the Nextcloud proxy relationship correctly

trusted_proxies

trusted_proxies accepts proxy IP addresses or CIDR ranges, not URLs. In a Compose deployment, container IP addresses can change, so trusting the dedicated Docker network subnet is often more stable than trusting one container address. Inspect the actual subnet before using the example:

docker network inspect proxy

Replace 172.20.0.0/16 with the subnet assigned to your proxy network. Keep this range as narrow as practical. Nextcloud treats trusted proxies as security-sensitive because an untrusted client could otherwise spoof forwarded headers.

overwriteprotocol and overwritehost

Traefik receives HTTPS from the browser and forwards HTTP to Nextcloud. OVERWRITEPROTOCOL=https tells Nextcloud to generate HTTPS URLs even though its container-side connection is HTTP. OVERWRITEHOST keeps generated links on the public hostname. These settings prevent mixed-content warnings, incorrect redirects, and links that expose an internal container address.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When several proxies are involved, overwritecondaddr can limit overwrite behavior to requests from a specific proxy IP. Use that only when you know the address seen by Nextcloud; a broad or incorrect condition can make the setting appear ineffective.

Rank #4
SANOOV Raspberry Pi 5 4GB Kit, 4GB RAM Single Board Computer with Active Cooler and ABS Case, Complete Raspberry Pi 5 Starter Kit for IoT Robotics Retro Gaming
  • All-in-One Complete Kit: This SANOOV RPi 5 bundle comes with Raspberry Pi 5 4GB RAM single board, active cooler, durable ABS case and screwdriver. No extra parts needed, ready to use right out of the box for beginners and hobbyists
  • Powerful Single Board Computer: Equipped with 4GB RAM and high-performance processor, delivers fast running speed for 4K playback, AI projects, programming and daily computing tasks. SANOOV for raspberry pi 5 4GB is equipped with broadcom 64 quad-core Arm Cortex A76 processor with gigabit ethernet and upgraded with IEEE 802.11ac Wi-Fi, Bluetooth 5.0 dual-band 2.4Ghz and 5Ghz and Power Over Ethernet (POE). Upgrading delivers 2-3 x speed vs Pi 4, redefining the experience
  • Efficient Active Cooler: Effectively lowers operating temperature and prevents performance throttling. Runs quietly even under long-time heavy load, ensures stable operation all day long. SANOOV RPi 5 4GB kit offer an active cooler, which combines an aluminium heatsink with a high-performance PWM fan. Active cooler is fully compatible with the Pi OS, which can effectively reduce the temperature of RPi5 and ensure its good performance during long-term high load operation
  • Sturdy ABS Protective Case: Well-fitted for Raspberry Pi 5 board, can be secured with 4 screws to effectively protect the Pi 5 motherboard from damage, reserves full access to all ports and buttons. SANOOV uses ABS material to produce the case, which has a softer texture and feel. Meanwhile, SANOOV case adopts a layered design for easy disassembly and installation. (Tip: The Case cannot install M.2 HAT Add on Board and Solid State Drive!)
  • Wide Application & Full Compatibility: Seamlessly compatible with official OS and mainstream peripheral accessories for Raspberry Pi 5. Whether you are a beginner, student, electronics hobbyist or professional developer, this all-in-one kit meets your diverse needs. It excels in IoT projects, robotics design, retro gaming devices, home media servers and other DIY creations. Backed by a large global community, you can easily find guides, technical support and shared projects online

Environment variables are not a removal mechanism

The official Docker image writes supported environment values into Nextcloud configuration. Removing TRUSTED_PROXIES or OVERWRITEPROTOCOL from Compose later does not necessarily remove values already written to the configuration file. Review the resulting configuration and change it deliberately with occ or by editing the persistent configuration through a controlled maintenance procedure.

Handle CalDAV and CardDAV discovery

Calendar and contact clients commonly request /.well-known/caldav and /.well-known/carddav. The Nextcloud Administration Manual’s Traefik guidance includes a redirect-regex middleware for these paths. Without equivalent redirects, the web interface can work while mobile or desktop calendar and contact clients fail autodiscovery.

Implement the middleware using the syntax for your installed Traefik release, then attach it to the HTTPS router. The intended result is that both well-known paths redirect to Nextcloud’s DAV endpoint at /remote.php/dav/. Test each path with a command such as:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -I https://cloud.example.com/.well-known/caldav
curl -I https://cloud.example.com/.well-known/carddav

Confirm that the response is an intentional redirect to the DAV endpoint, not a 404 or a redirect back to HTTP. Because exact label escaping differs between Compose formats and Traefik releases, verify the final regular expression against the Traefik v3 middleware reference before applying it.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Deploy and verify the stack

  1. Create the project directory, Compose file, static Traefik configuration, and persistent-data directories.
  2. Set strong database credentials and the real hostname. Keep DNS-provider credentials in the mechanism supported by your chosen ACME challenge.
  3. Confirm that the VPS firewall permits TCP 80 and 443 and that the DNS record resolves to the VPS.
  4. Start the stack with docker compose up -d.
  5. Watch startup output with docker compose logs -f traefik nextcloud.
  6. Open https://cloud.example.com. Complete the Nextcloud administrator setup if it was not initialized through environment variables.
  7. Check the certificate presented by the browser and verify that the router selected the intended resolver.
  8. Run the DAV checks and log in from a separate browser or client to confirm that generated URLs remain HTTPS.

For a first certificate request, a staging ACME certificate is safer while you are correcting DNS, challenge, and resolver settings. Once validation succeeds, switch to the production CA and remove any staging-only setting. This avoids consuming production rate limits during repeated tests.

Best Value
RasTech Raspberry Pi 5 8GB Kit with Active Cooler and Pi5 Case
  • 【What you Get】You will get 1*Pi 5 8GB Single Board,1*RasTech Case,1*Active Cooler,1*Screwdriver,1*Installation instructions,12-month free warranty, lifetime service, 24-hour prompt and friendly response.
  • 【More Connectors】There are two USB 3.0 ports(5Gbps simultaneously) and two USB 2.0 ports, which triple total bandwidth ,support any combination of up to two cameras or displays. Peak SD card performance is doubled through support for the SDR104 high-speed mode. It provides a smooth desktop experience for you. Offer Gigabit Ethernet and a PCIe interface, along with dual-band Wi-Fi and Bluetooth 5.0/BLE wireless capability. The RasTech Pi 5 Kit use the new 27W 5.1V 5A USB-C power connector.
  • 【 Support Dual 4Kp60 Display 】Each of the two microHDMI sockets can control a 4K display at 60 Hertz, now support HDR, offering super HD video for media streaming projects. RPi 5 is the first RPi model that comes with a PCI Express port (PCIe 2.0 x1 with 500 MB/s) to attach SSDs (requires separate M.2 HAT).
  • 【 Excellent Chips And Applications】Pi 5 is a full-size Pi computer using silicon built in-house at Pi. The RP1 “southbridge” provides the bulk of the I/O capabilities for Pi 5. Pi 5 is more friendly and convenient in the development of Internet of Things, Web development, machine identification, automatic control and other electronic equipment applications and network.
  • 【 Faster CPU, Better GPU 】 Pi 5 features a Broadcom BCM2712 64-bit quad-core Arm Cortex-A76 processor running at 2.4GHz, it delivers a 2–3× increase in CPU performance relative to RaspberryPi 4. The 800MHz VideoCore VII GPU is compatible to OpenGL ES 3.1 and Vulkan 1.2, substantial uplift in graphics performance. Pi 5 Offers lightning-fast CPU speed, a PCI Express interface, a Real Time Clock (RTC) and a power button and runs significantly cooler than Pi 4.

Troubleshooting by symptom

Symptom Likely cause Fix
Traefik reports a non-existent certificate resolver The resolver label does not exactly match the static configuration. Use the same case-sensitive name, such as letsencrypt, in both places and restart Traefik.
502 Bad Gateway Traefik is on the wrong network or is targeting the wrong container port. Keep traefik.docker.network=proxy, attach Nextcloud to that network, and target the internal port exposed by the container.
Redirect loop or mixed-content warnings Nextcloud sees the proxy’s HTTP connection instead of the original HTTPS request. Set OVERWRITEPROTOCOL=https, verify forwarded headers, and ensure the router terminates TLS only once.
Untrusted-domain error The public hostname is absent from Nextcloud’s trusted domains. Add the exact hostname through NEXTCLOUD_TRUSTED_DOMAINS during initialization or with the appropriate occ config:system:set trusted_domains command.
DAV clients cannot discover calendars or contacts The well-known paths are not redirected. Add and test the Traefik redirect-regex middleware for both CalDAV and CardDAV paths.
Proxy settings appear unchanged after editing Compose Existing values remain in persistent Nextcloud configuration. Inspect the configuration inside the container and remove or replace the values explicitly; deleting the environment entries alone is insufficient.
ACME validation fails DNS is stale, port 80 is blocked for an HTTP challenge, or DNS-provider credentials are invalid for a DNS challenge. Check public DNS, firewall rules, challenge logs, and provider permissions. Use the ACME staging CA while testing.

Security and maintenance decisions

Protect the Docker socket

Traefik needs access to Docker metadata to discover labels. A read-only socket mount reduces accidental writes, but access to the Docker socket remains highly privileged. Restrict VPS administration, keep the host patched, and do not expose the Docker API over TCP.

Keep the database private

Do not add a host port mapping for PostgreSQL. Nextcloud reaches it by the Compose service name on the internal network. Back up the database and test restoration instead of relying only on the filesystem volume.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Plan upgrades

Pin image versions, read the upgrade notes for the selected Nextcloud major release, and take a database plus data backup before changing images. Upgrade one major version at a time when the Nextcloud support policy requires it. Review Traefik labels after major Traefik upgrades because deprecated syntax can be removed.

Use narrow proxy trust

Trust only the network or addresses that can actually send requests to Nextcloud. A broad CIDR may make deployment easier but expands the set of sources allowed to influence proxy headers. Recheck the subnet after recreating networks or migrating the stack to another VPS.

Optional Nextcloud Talk scaling

Basic Talk calls can run without a separate high-performance backend, but larger deployments may add the Nextcloud Talk High Performance Backend and TURN/STUN services. Those components introduce additional routing, signaling, and UDP requirements that are separate from the basic HTTP router described here. Treat them as a second design: document the extra hostnames, ports, certificates, and firewall rules before exposing them.

When this architecture is the right choice

Traefik with Compose is a good fit when you want label-driven routing, automatic certificates, and several applications on one VPS. It is less suitable when you need a managed database, multi-node failover, or a platform that hides Docker and certificate operations. For a single VPS, the design remains straightforward as long as persistent storage, proxy trust, and backups are handled as production concerns rather than setup details.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

Bestseller No. 1
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
Includes Raspberry Pi 5 with 2.4Ghz 64-bit quad-core CPU (8GB RAM); CanaKit Turbine Black Case for the Raspberry Pi 5
$259.95
Bestseller No. 2
CanaKit Raspberry Pi 5 16GB Starter Kit PRO - Turbine Black (128GB Edition) (16GB RAM)
CanaKit Raspberry Pi 5 16GB Starter Kit PRO - Turbine Black (128GB Edition) (16GB RAM)
Includes Raspberry Pi 5 16GB with 2.4Ghz 64-bit quad-core CPU (16GB RAM); CanaKit Turbine Black Case for the Raspberry Pi 5
$419.99
Bestseller No. 3
CanaKit Raspberry Pi 5 Essentials Starter Kit (4GB RAM)
CanaKit Raspberry Pi 5 Essentials Starter Kit (4GB RAM)
CanaKit Raspberry Pi 5 Essentials Starter Kit
$189.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.