Use webdav from a different domain

Hello,
I am trying to use a different domain for webdav connections to avoid problems during uploads due to cloudflare proxy limit of 100 or 200 mb.

What I actually achieved is:

domain.com → nextcloud instance (behind cloudflare proxy)
dav.domain.com/url → all paths are redirected to domain .com/url except for /remote.php/dav/files/user that works as reverse proxy to localhost/remote.php/dav/files/user (no cloudflare proxy)

Now what I want to achieve is that domain.com/remote.php/dav/files/user is redirected to dav.domain.com/remote.php/dav/files/user (no reverse proxy because otherwise I am under cloudflare proxy limit)

I tried with nginx to do a return 302 dav.domain.com$request_uri but both nautilus and nextcloud can’t access via webdav anymore, due to the redirect:

    location /remote.php/dav/files {
        return 307 https://dav.domain.com$request_uri; # tried with 301, 302 and 307
        # proxy_pass https://dav.domain.com; <- this works but i am behind cloudflare proxy so I didn't achieved my goal
    }

Nextcloud version (eg, 20.0.5): 26.0.11
Operating system and version (eg, Ubuntu 20.04): Debian 12
Apache or nginx version (eg, Apache 2.4.25): Nginx 1.18
PHP version (eg, 7.4): fpm 8.1

Thank you!

Do you use nginx or apache2 for Nextcloud? Why not second name for the Nextcloud (trusted hosts in Nextcloud).

With different subdomains, does it not get tricky with authentication and cookies and stuff?

Even if you manage to do that, all “dynamic” queries then are not very efficient, because of all dynamic content, you ask first cloudflare, it redirects to your server, it gives the 307 redirect response temporarily to your subdomain and you have to send a second query to the subdomain.

Then, what is the purpose of putting cloudflare there in the first place?