How to reverse proxy WebDAV url using nginx

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 20.0.5): 21.0.1
Operating system and version (eg, Ubuntu 20.04): Ubuntu 20.04
Apache or nginx version (eg, Apache 2.4.25): nginx 1.18.0
PHP version (eg, 7.4): 8.0

The issue you are facing: Cannot reverse proxy WebDAV url using nginx. I can get the common WebDAV url as https://example.com/remote.php/webdav, but I want to make it shorter, using subdomains like https://dav.example.com.

Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:

  1. Setup NextCloud as normal
  2. In /etc/nginx/conf.d/dav.conf, I wrote as follows:
server {
    listen 443 ssl;
    server_name dav.example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    location / {
        proxy_set_header Host example.com;
        proxy_pass https://example.com/remote.php/webdav;
    }
}
  1. Access https://dav.example.com using normal WebDAV client, and I get following file list:
- Folder 1
- Folder 2
- Folder 3
...
- webdav
  1. Even if I click any folder, I can’t see any contents of them.

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'passwordsalt' => '****',
  'secret' => '****',
  'trusted_domains' =>
  array (
    0 => 'localhost',
    1 => 'example.com',
  ),
  'datadirectory' => '/usr/share/nginx/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '21.0.1.1',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextuser',
  'dbpassword' => '****',
  'installed' => true,
  'instanceid' => '****',
  'skeletondirectory' => '',
  'overwrite.cli.url' => 'https://example.com',
);

The output of your Apache/nginx/system log in /var/log/____:

192.168.1.1 - - [06/May/2021:18:39:25 +0900] "PROPFIND /remote.php/webdav/Private/ HTTP/2.0" 200 1281 "-" "Transmit/5.7.4"
192.168.1.1 - - [06/May/2021:18:39:25 +0900] "PROPFIND /remote.php/webdavremote.php/webdav/Private/ HTTP/1.0" 200 3306 "-" "Transmit/5.7.4"

From the nginx log, I think this issue is caused by infinite redirect of path, but I don’t know how to resolve it.