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',
| Setting | When to use it | Example value |
|---|---|---|
overwritehost | Nextcloud detects the wrong hostname. Hostname setting | cloud.example.com |
overwritewebroot | Nextcloud detects the wrong web path for a site served under /nextcloud. Webroot setting | /nextcloud |
overwrite.cli.url | Set 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 setting | https://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.