Transparently proxy host.tld/nextcloud to nextcloud.host.tld

Hi. I’m currently running NC as a subdirectory of a host (host.tld/nextcloud). We now need to move it to another location on a dedicated hostname (nextcloud.host.tld), and we’d like to keep working both the urls.

In the trusted_domains params we added the urls, now I need to figure out how to proxy requests from the old host (running nginx) to the new installation.

We tried:

    location ^~ /nextcloud/ {
       proxy_pass https://nextcloud.host.tld/;
       proxy_set_header        X-Real-IP       $remote_addr;
       proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_buffering off;
    }

and works for the html part, but all the other elements (js, css…) return 404 because they’re attempted on the / of host.tld. I.e. an image is loaded as host.tld/a.jpg instead of host.tld/nextcloud/a.jpg.

In config we have:

  'overwrite.cli.url' => 'https://nextcloud.host.tld',
  'overwriteprotocol' => 'https',

We tried adding (according to this page)

  'trusted_proxies'   => ['75.119.1.1'], // this is the host running host.tld
  'overwritehost'     => 'host.tld',
  'overwriteprotocol' => 'https',
  'overwritewebroot'  => '/nextcloud',
  'overwritecondaddr' => '^75\.119\.1\.1$',

but this rewrites all requests to the old url, even the ones landing directly on nextcloud.host.tld.

Is this possible or shall we run NC in a subdirectory on the new host as well?
thanks

Yes with the webroot-setting, that is a global setting, so you can either run Nextcloud in a subfolder or not, but not both. But it would be possible to run it on two different subdomains at the same time.

A second installation with the same settings except for the subfolder in the URL, not sur, it could work. Perhaps with the session handling could get a problem.

Do you need both accesses? You can normally create a permanent redirect, the clients should then update the URL. And for old shared links, you can keep the redirect.

What do you mean, a 301 redirect? That will work for the Windows and mobile clients?

Exactly. In the desktop client, the feature was implemented: Save the new URL when hitting a permanent redirection 301 · Issue #5972 · owncloud/client · GitHub and I used it some time ago to change a URL.
For the mobile clients, I can’t remember. Check out the code or bugtracker, or test it, either on a test setup or only sending the permanent redirects to specific clients of your that you test it with.

Thanks for the hint.
I made a quick test and it works but requires reauthentication of the client. Is this an expected behaviour?

I thought it is working without re-authentication. For me it was within the same domain, so perhaps if the domain changes, something with the session management might no be valid any more. But that is just a guess, I don’t really know how to verify this…

I must say I did the test on two separate NC installations, so I logged in on the current one on the old host, switched the proxy and then I was headed on an old cloned version, so it could be that.