Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
VGSources
Blog

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

A practical guide to running Nextcloud behind Traefik on a VPS, covering Compose networks, v3 labels, Let's Encrypt, trusted proxies, HTTPS redirects and troubleshooting.
Length8 min Posted Quest giverVGSources Team

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.

Nextcloud works reliably behind Traefik on a VPS when the stack is split into three roles: Nextcloud serves the application, a database stores its data, and Traefik terminates HTTPS and forwards requests over a Docker network. The critical details are using matching Traefik v3 labels, configuring the certificate resolver consistently, and telling Nextcloud which proxy and protocol to trust.

What the architecture looks like

A practical deployment has Traefik, Nextcloud and a database running as Compose services. Traefik is the only service exposed to the public internet. It listens on ports 80 and 443, obtains and renews the TLS certificate, then routes the hostname you choose (for example, cloud.example.com) to the Nextcloud container. The database remains on an internal Docker network and has no public port mapping.

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.
Component Purpose Network exposure
Traefik Reverse proxy, HTTPS entry point, certificate resolver and router Public ports 80 and 443
Nextcloud Web application and WebDAV endpoint Attached to Traefik’s network and the private application network
Database Stores users, metadata, shares and application state Private network only; no host port required
Persistent volumes Keep Nextcloud files, database data, Traefik state and ACME data across upgrades Stored on the VPS and included in backups

Use separate Docker networks when possible. A proxy network lets Traefik reach Nextcloud, while an internal network carries database traffic. Nextcloud can join both networks; the database should join only the internal one. This limits accidental exposure and makes the intended traffic paths obvious.

Prepare the VPS before starting Compose

Choose DNS and a hostname

Create an A record for the cloud hostname pointing to the VPS’s public IPv4 address. If the VPS has IPv6 and you publish an AAAA record, ensure the server firewall and Traefik listen on IPv6 too; an incorrect AAAA record can make some clients fail even when IPv4 works. Wait for DNS to resolve before requesting a production certificate.

#1 Best Overall
Sale
UGREEN NAS DH2300 2-Bay for Beginners & Personal Users, Phone Backup | AI Album, Private Cloud/Remote Access, File Sharing, Multi-Device Backup, Home Entertainment, 4GB RAM on Board (Diskless)
  • Entry-level NAS Personal Storage:UGREEN NAS DH2300 is your first and best NAS made easy. It is designed for beginners who want a simple, private way to store videos, photos and personal files, which is intuitive for users moving from cloud storage or external drives and move away from scattered date across devices. This entry-level NAS 2-bay perfect for personal entertainment, photo storage, and easy data backup (doesn't support Docker or virtual machines).
  • Set Your Devices Free, Expand Your Digital World: This unified storage hub supports massive capacity up to 64TB.*Storage drives not included. Stop Deleting, Start Storing. You can store 22 million 3MB images, or 2 million 30MB songs, or 43K 1.5GB movies or 67 million 1MB documents! UGREEN NAS is a better way to free up storage across all your devices such as phones, computers, tablets and also does automatic backups across devices regardless of the operating system—Window, iOS, Android or macOS.
  • The Smarter Long-term Way to Store: Unlike cloud storage with recurring monthly fees, a UGREEN NAS enclosure requires only a one-time purchase for long-term use. For example, you only need to pay $459.98 for a NAS, while for cloud storage, you need to pay $719.88 per year, $2,159.64 for 3 years, $3,599.40 for 5 years. You will save $6,738.82 over 10 years with UGREEN NAS! *NAS cost based on DH2300 + 12TB HDD; cloud cost based on 12TB plan (e.g. $59.99/month).
  • Blazing Speed, Minimal Power: Equipped with a high-performance processor, 1GbE port, and 4GB RAM on Board, this NAS handles multiple tasks with ease. File transfers reach up to 125MB/s—a 1GB file takes only 8 seconds. Don't let slow clouds hold you back; they often need over 100 seconds for the same task. The difference is clear.
  • Let AI Better Organize Your Memories: UGREEN NAS uses AI to tag faces, locations, texts, and objects—so you can effortlessly find any photo by searching for who or what's in it in seconds. It also automatically finds and deletes similar or duplicate photo, backs up live photos and allows you to share them with your friends or family with just one tap. Everything stays effortlessly organized, powered by intelligent tagging and recognition.

Open only the required ports

Allow SSH on the port you administer, plus TCP 80 and 443. Port 80 is useful for ACME HTTP challenges and for redirecting plain HTTP to HTTPS. Do not publish the database port or Nextcloud’s internal port. A host firewall such as UFW should express that policy, while your VPS provider’s firewall must allow the same ports.

Create directories and protect secrets

Place the Compose project in a dedicated directory owned by an administrative account. Create persistent locations for the Nextcloud files, the database, Traefik’s dynamic state and its ACME file. The ACME file contains account and certificate information; restrict it to the user running Traefik (commonly mode 600). Keep database passwords and DNS-provider credentials in an environment file or Docker secrets rather than committing them to a repository.

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

Build the Compose stack

The exact image tags should be pinned to versions you have tested together; the available Nextcloud and Traefik releases change over time. The important Compose relationships are the networks, persistent volumes and labels. A minimal Nextcloud service has the following shape:

services:
  nextcloud:
    image: nextcloud:apache
    networks:
      - proxy
      - internal
    depends_on:
      - db
    environment:
      TRUSTED_PROXIES: 172.20.0.0/16
      OVERWRITEPROTOCOL: https
    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

  db:
    image: postgres
    networks:
      - internal

networks:
  proxy:
  internal:

The example illustrates the routing contract rather than a version recommendation. Replace the database image with a currently supported database and pin both images after checking compatibility. Add the database volume, Nextcloud’s data and configuration volumes, and Traefik’s configuration and ACME volumes before using this in production.

Rank #2
Sale
UGREEN NAS DXP2800 2-Bay for Advanced Home Users, Remote Workers & Creators | Home Media & Data Center, Docker & VM, Plex, Fast File Transfer, Intel N100, 8GB DDR5, 2.5GbE, 2x M.2 NVMe, 4K HDMI(Diskless)
  • 【Advanced Home Data & Media Hub】For advanced home users who need phone backup, file storage, and centralized data management. Centralize family photos, 4K videos, movies, computer backups, and personal files in one place while running multiple apps for home entertainment and everyday data management. Suitable for households with growing digital libraries and multiple NAS use cases.
  • 【Built for Creators, Media Servers & Advanced Apps】Powered by the Intel N100 Quad-Core CPU, 8GB DDR5 RAM, 2.5GbE networking, and dual M.2 NVMe slots, DXP2800 handles large files and heavier workloads with ease. Run Docker, virtual machines, and media server applications compatible with Plex—ideal for content creators, tech enthusiasts, and advanced home users managing 4K videos, RAW photos, personal media libraries, and multiple NAS apps.
  • 【Up to 80TB for Growing Digital Libraries】 Supports up to 80TB of storage using two HDD bays and two M.2 NVMe SSD slots for family photos, movies, RAW photos, 4K videos, work files, and device backups. AI photo management supports recognition of people, objects, scenes, and locations, album organization, and duplicate photo detection. HDDs and SSDs are not included.
  • 【AI-powered Home Surveillance】Turn DXP2800 into a centralized home surveillance hub by connecting compatible network cameras and storing recordings locally on your NAS. AI-powered features include Face Recognition, People Detection, and Pet Detection, helping advanced home users review important events more efficiently while managing home surveillance and personal data in one place.
  • 【One data Center Across Your Devices】Keep files from desktops, laptops, phones, tablets, and other devices together instead of scattered across cloud accounts and external drives. Access, back up, organize, and share data across Windows, macOS, Android, iOS, web browsers, and compatible smart TVs—ideal for creators and advanced home users working across multiple devices.

Why each Traefik label matters

  • traefik.enable=true opts the container into Docker-provider discovery.
  • traefik.docker.network=proxy prevents Traefik from selecting the wrong network when Nextcloud is attached to more than one.
  • The router rule matches only the chosen hostname; requests for another host are not sent to Nextcloud.
  • The secure entry point and tls=true make the router terminate HTTPS.
  • tls.certresolver=letsencrypt selects the resolver configured in Traefik’s static configuration.
  • loadbalancer.server.port=80 tells Traefik which container port to use, even though that port is not published on the VPS.

Traefik’s Docker provider documentation deprecates the ruleSyntax label and says it will be removed in the next major version. Write rules using Traefik v3 syntax rather than carrying an old v2 compatibility label forward.

Configure Traefik and Let’s Encrypt

Traefik has static settings (entry points, providers and certificate resolvers) and dynamic settings (routers, services and middlewares). Keep the resolver name identical in both places. Resolver names are case-sensitive: letsencrypt and letsEncrypt are different names, and a mismatch produces a “non-existent certificate resolver” error.

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.
certificatesResolvers:
  letsencrypt:
    acme:
      email: [email protected]
      storage: /letsencrypt/acme.json
      httpChallenge:
        entryPoint: web

Mount the directory containing acme.json into the Traefik container and make the file writable by Traefik but not by ordinary users. A DNS challenge is another option, especially when port 80 cannot be used or when you need wildcard certificates; it requires credentials for your DNS provider and a provider-specific challenge configuration.

Use the staging authority first

Repeated failed production requests can trigger Let’s Encrypt rate limits. Test the resolver against the staging certificate authority while you correct DNS, entry points and permissions, then switch to production only after a complete issuance succeeds. Staging certificates are intentionally untrusted by browsers, so a warning during this test is expected.

Rank #3
BUFFALO LinkStation 210 4TB 1-Bay NAS Network Attached Storage with HDD Hard Drives Included NAS Storage that Works as Home Cloud or Network Storage Device for Home
  • Value NAS with RAID for centralized storage and backup for all your devices. Check out the LS 700 for enhanced features, cloud capabilities, macOS 26, and up to 7x faster performance than the LS 200.
  • Connect the LinkStation to your router and enjoy shared network storage for your devices. The NAS is compatible with Windows and macOS*, and Buffalo's US-based support is on-hand 24/7 for installation walkthroughs. *Only for macOS 15 (Sequoia) and earlier. For macOS 26, check out our LS 700 series.
  • Subscription-Free Personal Cloud – Store, back up, and manage all your videos, music, and photos and access them anytime without paying any monthly fees.
  • Storage Purpose-Built for Data Security – A NAS designed to keep your data safe, the LS200 features a closed system to reduce vulnerabilities from 3rd party apps and SSL encryption for secure file transfers.
  • Back Up Multiple Computers & Devices – NAS Navigator management utility and PC backup software included. NAS Navigator 2 for macOS 15 and earlier. You can set up automated backups of data on your computers.

Redirect HTTP and preserve WebDAV discovery

Most users should be redirected from the plain HTTP entry point to HTTPS. Nextcloud also needs the CalDAV and CardDAV discovery paths under /.well-known to reach the DAV endpoint. The Nextcloud Administration Manual’s Traefik guidance uses a redirect-regex middleware for these paths. Apply that middleware to the HTTP and HTTPS routers according to the current Traefik label syntax; do not copy a Traefik 1 example into a Traefik 3 stack unchanged.

Tell Nextcloud that Traefik is the proxy

Nextcloud must distinguish the client-facing HTTPS request from the internal HTTP hop between Traefik and the container. Set trusted_proxies to the address or CIDR of the proxy that Nextcloud is allowed to trust, and set overwriteprotocol to https when protocol detection otherwise reports HTTP. The official Docker image exposes these settings through environment variables including TRUSTED_PROXIES and OVERWRITEPROTOCOL.

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

A Docker container’s IP can change when the stack is recreated. For that reason, trusting a dedicated Docker network subnet is often more stable than trusting one container address, provided that the subnet is exclusive to your reverse proxy path. Restrict the subnet carefully: trusted_proxies is a security boundary, not a list of arbitrary URLs. Its value must be an array of IP addresses or CIDR ranges, such as ['172.20.0.0/16'], never a hostname or URL.

If only one known proxy address should receive overwritten host or protocol values, Nextcloud also supports overwritecondaddr. This limits the overwrite to requests from that proxy IP. Secure the proxy host and its network as you would the Nextcloud server because a trusted proxy can otherwise spoof client-facing headers.

Rank #4
BUFFALO LinkStation 210 2TB 1-Bay NAS Network Attached Storage with HDD Hard Drives Included NAS Storage that Works as Home Cloud or Network Storage Device for Home
  • Value NAS with RAID for centralized storage and backup for all your devices. Check out the LS 700 for enhanced features, cloud capabilities, macOS 26, and up to 7x faster performance than the LS 200.
  • Connect the LinkStation to your router and enjoy shared network storage for your devices. The NAS is compatible with Windows and macOS*, and Buffalo's US-based support is on-hand 24/7 for installation walkthroughs. *Only for macOS 15 (Sequoia) and earlier. For macOS 26, check out our LS 700 series.
  • Subscription-Free Personal Cloud – Store, back up, and manage all your videos, music, and photos and access them anytime without paying any monthly fees.
  • Storage Purpose-Built for Data Security – A NAS designed to keep your data safe, the LS200 features a closed system to reduce vulnerabilities from 3rd party apps and SSL encryption for secure file transfers.
  • Back Up Multiple Computers & Devices – NAS Navigator management utility and PC backup software included. NAS Navigator 2 for macOS 15 and earlier. You can set up automated backups of data on your computers.

Environment variables are written into Nextcloud’s configuration during container initialization. Removing a variable later does not necessarily remove the value already stored in config.php. If you change proxy settings, inspect the generated configuration and remove or correct stale entries deliberately, then restart the container.

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

Start the stack and verify it in order

  1. Validate the Compose file with docker compose config. Check that network names, volume paths and environment variables resolve as intended.
  2. Start the services with docker compose up -d, then inspect docker compose logs -f traefik and docker compose logs -f nextcloud.
  3. Confirm that the hostname resolves to the VPS and that ports 80 and 443 are reachable from an external network.
  4. Open https://cloud.example.com. The certificate should contain the hostname, and the request should reach Nextcloud rather than a Traefik default router.
  5. Complete the Nextcloud web installer using the database service name as the database host, not localhost. Create the administrator account and verify that the data directory is on a persistent volume.
  6. Test a file upload, a second browser session and a WebDAV client. Check that HTTP redirects to HTTPS and that no mixed-content warning appears.
  7. After the staging test succeeds, switch the ACME endpoint to production, remove any staging certificate state as appropriate, and watch Traefik logs for a successful renewal.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common failures and precise fixes

“Bad Gateway” or a router with no service

  • Check that Nextcloud and Traefik share the network named by traefik.docker.network.
  • Confirm that the load-balancer port is the port Nextcloud listens on inside the container, not a host-published port.
  • Read Traefik’s discovered configuration in its logs and verify the router’s host rule exactly matches the requested hostname.

Certificate resolver not found

Compare the resolver key under certificatesResolvers with the router label character by character, including capitalization. Restart Traefik after changing static configuration; labels alone cannot create a missing resolver.

Certificate issuance fails

  • Verify the A and AAAA records point to this VPS and that no proxying service is sending the challenge elsewhere.
  • Ensure TCP 80 is reachable for an HTTP challenge, or verify DNS API credentials and propagation for a DNS challenge.
  • Use the staging authority while diagnosing repeated failures, then return to production after the configuration is stable.

Nextcloud reports an untrusted domain or redirects endlessly

Add the public hostname to Nextcloud’s trusted_domains, ensure TRUSTED_PROXIES contains the actual proxy network, and set OVERWRITEPROTOCOL=https. A loop usually means Traefik terminates TLS but Nextcloud believes the original request was HTTP.

Calendar and contacts do not discover the DAV endpoint

Inspect requests to /.well-known/caldav and /.well-known/carddav. They should be redirected to Nextcloud’s DAV path by the dedicated redirect-regex middleware. Check the middleware attachment on the relevant router and make sure an old Traefik 1 label syntax has not been mixed into a Traefik 3 configuration.

Best Value
BUFFALO LinkStation 210 6TB 1-Bay NAS Network Attached Storage with HDD Hard Drives Included NAS Storage that Works as Home Cloud or Network Storage Device for Home
  • Value NAS with RAID for centralized storage and backup for all your devices. Check out the LS 700 for enhanced features, cloud capabilities, macOS 26, and up to 7x faster performance than the LS 200.
  • Connect the LinkStation to your router and enjoy shared network storage for your devices. The NAS is compatible with Windows and macOS*, and Buffalo's US-based support is on-hand 24/7 for installation walkthroughs. *Only for macOS 15 (Sequoia) and earlier. For macOS 26, check out our LS 700 series.
  • Subscription-Free Personal Cloud – Store, back up, and manage all your videos, music, and photos and access them anytime without paying any monthly fees.
  • Storage Purpose-Built for Data Security – A NAS designed to keep your data safe, the LS200 features a closed system to reduce vulnerabilities from 3rd party apps and SSL encryption for secure file transfers.
  • Back Up Multiple Computers & Devices – NAS Navigator management utility and PC backup software included. NAS Navigator 2 for macOS 15 and earlier. You can set up automated backups of data on your computers.

Settings return after you remove environment variables

Read Nextcloud’s persistent config.php. The Docker entrypoint may have already written the values, so removing the environment variable does not undo them. Correct the stored settings, preserve the intended proxy subnet, and restart the service.

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

Backups, upgrades and hardening

Back up both the database and the Nextcloud data/configuration volumes; either alone is insufficient for a consistent restore. Include Traefik’s ACME storage so certificate-account state survives a VPS rebuild, while keeping a secure copy of the relevant secrets. Test restoring to a separate directory rather than assuming a successful archive means a usable backup.

Upgrade one layer at a time: back up, read the release notes for the chosen Nextcloud and database versions, recreate the database or application container with the pinned tag, and watch logs before moving to the next component. Keep Traefik’s major-version syntax consistent, especially around router rules and middleware labels. Remove unused public ports, restrict SSH, apply operating-system security updates, and monitor disk space because file versions, previews and database growth can fill a small VPS unexpectedly.

When this design is the right fit

This pattern suits a single VPS or a small number of services that need one HTTPS ingress point. Traefik’s label-driven routing makes adding another Compose application straightforward, while Nextcloud remains isolated from the public network. It is less suitable when you need a managed database, multi-node failover or a dedicated high-availability design; those requirements add storage, database and coordination concerns that Docker Compose on one VPS does not solve.

Nextcloud Talk’s High Performance Backend and TURN/STUN introduce additional services and UDP routing requirements. Treat those as a separate design exercise rather than assuming the basic web router handles real-time media traffic.

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

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 quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

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.