How to change the root URL path of Nextcloud?

I installed a Nextcloud server for my family only. I want to mitigate the probing from the internet by prefix the Nextcloud root URL path.

Give 2 examples:

  1. from https://nextcloud.example.com/index.php/login to https://nextcloud.example.com/a/prefix/path/index.php/login
  2. from https://nextcloud.example.com/remote.php/dav/files/john/ to
    https://nextcloud.example.com/a/prefix/path/remote.php/dav/files/john/

If the visitors access to incorrect prefix, then the web server will return the 403. The web server configurations are not the problems to me, but I need to know how to configure the nextclound’s config.php for this. And also how to configure this prefix to the Nextcloud Android App.

1 Like

I think it is because of rewrite in nextcloud not possible. Use perhaps two subdomains. Rewrite is in .htaccess

So, I suppose that Nextcloud doesn’t have such feature. This tells me that I need to issue a feature request.

You can install Nextcloud in sub dirs e.g. https://cloud.server.tld/path/

1 Like

Then do you know how can I change this for an existing installation ?

I found the solution according to Nextcloud’s official manuals.

To add a URL prefix for an existing Nextcloud installation, one should do following steps:

1: Configure the HTTP server of the existing Nextcloud installation.

Change the DocumentRoot to a dummy directory and add restrictions to the dummy directory as deny all requests.

Then add an Alias to the wanted prefix to the real directory of the existing Nextcloud installation (which should be the original DocumentRoot).

#DocumentRoot /Org/Install/Dir/
DocumentRoot /Dummy/Dir/
<Directory "/Dummy/Dir/">
  Require all denied
</Directory>
Alias "/My/Wanted/Prefix/" "/Org/Install/Dir/"

Then restart the HTTP server. And as you know, my example here is for Apache web server.

2: Configure Nextcloud’s config.php

Find the line below:
'overwrite.cli.url' => '',
change to
'overwrite.cli.url' => 'https://mycloud.example.com/My/Wanted/Prefix',

3: Configure Nextcloud Android App

Actually , I can find no way to change the existing login of the Nextcloud Android App. I managed to uninstall the Nextcloud Android App then install it back to begin the login process. Maybe there are smarter methods like delete cache and local storage etc.

Anyway, at the login place you should choose the private installation and at the URL field fill up the URL as https://mycloud.example.com/My/Wanted/Prefix

References: Nextcloud Administration Manual and Nextcloud Android Manual

1 Like

Using the docker image since I am using an old mac as my server, but when I do this every page returns a 403. This is what I did in the apache site config:

#    DocumentRoot /var/www/html
    DocumentRoot /Dummy/Dir/
    <Directory "/Dummy/Dir/">
      Require all denied
    </Directory>
    Alias "/nextcloud/" "/var/www/html/"

And config.php

'overwrite.cli.url' => 'http://192.168.1.12:5676/nextcloud'

docker-compose:
NEXTCLOUD_TRUSTED_DOMAINS: nc-server
OVERWRITEHOST: nchost.dev:9998
OVERWRITEPROTOCOL: http
OVERWRITEWEBROOT: /nc

nginx:
server {
listen 80;
proxy_set_header Host $host;

location /nc {
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    rewrite /nc/(.*) /$1 break;
    proxy_pass http://nc-server;
}

}

If I understand correctly, nginx rewrite response the redirection to the client. This means client would know the real URI.

The ideal solution should be nginx serves /nc/* as the nextcloud root but block all other ‘/*’ requests.

It seems that my original solution failed in recent Nextcloud versions.

I wish there is official solution for this.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.