setup

Nextcloud Reverse Proxy Config for Trusted Proxies and DAV

Configure Nextcloud trusted proxies and HTTPS URL generation, then add and verify CalDAV and CardDAV discovery redirects on NGINX.

Illustrated title card for the guide: Nextcloud Reverse Proxy Config for Trusted Proxies and DAV

In Nextcloud’s config/config.php, add the reverse proxy’s IP to trusted_proxies. Set overwriteprotocol to https if Nextcloud generates HTTP URLs for a public HTTPS site. On the proxy, redirect /.well-known/caldav and /.well-known/carddav to Nextcloud’s DAV endpoint. Nextcloud reverse proxy configuration

Trust the proxy and pass the client IP

This example assumes one NGINX proxy that receives HTTPS directly from clients and forwards requests to an existing Nextcloud installation. Replace 10.0.0.1 with the proxy address that Nextcloud sees as the request’s REMOTE_ADDR. For a single proxy, list its individual address. Nextcloud also accepts IPv4 or IPv6 CIDR ranges when the range belongs to proxies you trust. Nextcloud trusted proxy settings

On NGINX, add or update these directives in the existing location that contains proxy_pass for Nextcloud. NGINX proxy configuration example

proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;

Carry over any other proxy_set_header directives that this location needs. A location inherits proxy_set_header directives only if it defines none of its own. NGINX header inheritance

Add or update this entry inside the existing $CONFIG array in config/config.php. Nextcloud uses X-Forwarded-For by default for requests from trusted proxies. If you already override forwarded_for_headers, use ['HTTP_X_FORWARDED_FOR'] with the NGINX example above. An incorrect forwarded_for_headers setting can let clients spoof the IP Nextcloud records. Nextcloud trusted proxies and forwarded headers

'trusted_proxies' => ['10.0.0.1'],

Keep the public hostname, such as cloud.example.com, in trusted_domains. That list controls which hostnames users can log in through. Nextcloud trusted domains

Fix HTTPS URL generation

If the proxy handles HTTPS and Nextcloud generates links starting with http://, add or update this entry in the same $CONFIG array. Omit overwriteprotocol or leave it empty if automatic detection already gives the correct scheme. Nextcloud overwrite parameters

'overwriteprotocol' => 'https',
SettingWhen to use itExample value
overwritehostNextcloud detects the wrong hostname. Hostname settingcloud.example.com
overwritewebrootNextcloud detects the wrong web path for a site served under /nextcloud. Webroot setting/nextcloud
overwrite.cli.urlSet the public base URL for links generated by command-line tools such as cron and occ. Include the subfolder if the public URL uses one. Command-line URL settinghttps://cloud.example.com/nextcloud

Redirect CalDAV and CardDAV discovery

If Nextcloud also uses NGINX as its web server, add or update these locations in the reverse proxy’s server block for your public hostname. This example serves Nextcloud at the root of https://cloud.example.com. Nextcloud’s NGINX reverse proxy example

location /.well-known/caldav {
    return 301 $scheme://$host/remote.php/dav;
}

location /.well-known/carddav {
    return 301 $scheme://$host/remote.php/dav;
}

If users open Nextcloud at https://cloud.example.com/nextcloud, point both redirects to https://cloud.example.com/nextcloud/remote.php/dav. The two incoming discovery paths still start at /.well-known/ on the public hostname. Nextcloud service discovery URLs

Check both redirects

Run nginx -t on the proxy to check its configuration. If the check passes, apply the changes with nginx -s reload. NGINX command-line options

From a client, replace cloud.example.com with your public hostname and check the response headers for both discovery URLs. curl HEAD option

curl --head https://cloud.example.com/.well-known/caldav
curl --head https://cloud.example.com/.well-known/carddav

Both responses should show 301 and a Location of https://cloud.example.com/remote.php/dav for the root installation. For the subfolder example, look for https://cloud.example.com/nextcloud/remote.php/dav. Nextcloud NGINX redirect rules · Nextcloud DAV endpoints · curl redirect headers

Evidence and limits. The Nextcloud 33 Administration Manual, NGINX documentation, and curl manual were checked on November 26, 2026. The configuration and commands were not run on a Nextcloud deployment.

Sources

  1. Nextcloud 33 Administration Manual · Reverse proxy docs.nextcloud.com
  2. Nextcloud 33 Administration Manual · Configuration parameters docs.nextcloud.com
  3. Nextcloud 33 Administration Manual · General troubleshooting docs.nextcloud.com
  4. NGINX documentation · Setting up an NGINX demo environment docs.nginx.com
  5. NGINX documentation · HTTP proxy module nginx.org
  6. NGINX documentation · Command-line parameters nginx.org
  7. curl manual curl.se

Related