Nextcloud change domain url from example.com/nextcloud to example.com/

Well basically, I have nextcloud installed and it is accessible from example.com/nextcloud but I want it to be accessible at example.com/

When I did change the url and renamed the folder it just said forbidden. I am quite new to this and don’t know a lot. How could I do that?

1 Like

For sure. Assign any trusted domain you own. example.com is totally fine.

or, Read the documentation at:

https://docs.nextcloud.com/server/latest/admin_manual/

Search similar questions on this forum, or the greater internet for this question. Lots of good info out there.

You will need to own the domain you use. Once you tell nextcloud to look for that domain you are good to go (as far as Nextcloud itself is concerned). Check your domain registrar if more work is needed. Cheers!

No no I already have my domain and it’s already added to the trusted domain. It is just that nextcloud is accessible when I type in the domain followed by /nextcloud but I want the url to be prettier and be accessible just from / as in example.con/ instead of example.com/nextcloud

What web server are you using? Please post your web server / VirtualHost config. You most likely also have to change the ServerAlias, ServerName and DocumentRoot directives accordingly.

I am using apache2 that is running on Ubuntu 18.04 on WLS. Like I mentioned I am quite new so I do not know where I can find any of the configuration files.

Did you use a specific tutorial in order to install it? The main apache config file apache2.conf resides in/etc/apache2 and the VirtualHosts, if you configured any, reside in /etc/apache2/sites-available.

Here are the configs:

apache2.conf
000-default.conf

If you only using Nextcloud on this server you can just change the DocumentRoot directive to /var/www/html/nextcloud or whatever you called the folder in which you installed Nextcloud.

If you run multiple sites / apps on that server or if you are planing to to do so, you should use a sub domain like cloud.example.com and then of course also point the Document Root to your Nextcloud folder instead of to the folder above it.

Only cloud is being run from there. From searching online I already found a resource that suggested changing it. But after changing that DocumentRoot and restarting the apache service nothing changed. It was still the same way.

Yeah there is more to it, I didn’t think of…

First of all you have to make the changes to the the conf file your acme client created, because you’re redirecting to https in your 000-default.conf. It’s probaby named 000-default-le-ssl.conf if you used certbot to create the certificates.

nano /etc/apache2/sites-available/000-default-le-ssl.conf and make sure it looks something like this:

<VirtualHost *:443>
  DocumentRoot /var/www/html/nextcloud
  ServerName  example.com

  <Directory /var/www/html/nextcloud/>
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews

    <IfModule mod_dav.c>
      Dav off
    </IfModule>
  </Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# Lines automatically added by certbot DO NOT CHANGE OR REMOVE!:
SSLEngine on
SSL CertificateFile............
SSL CertificteKeyFile........
Include /etc/letsencrypt..........

</VirtualHost>

In your 000-default.conf you can then remove almost everything except for the following:

<VirtualHost *:80>
ServerName example.com

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

#Lines automatically added by certbot DO NOT CHANGE OR REMOVE!:
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

Then you also have to edit the following lines in your config.php file:

nano /var/www/html/nextcloud/config/config.php
'trusted_domains' => 
  array (
    0 => 'example.com',
  ),

'overwrite.cli.url' => 'https://example.com',
'overwriteprotocol' => 'https',
'htaccess.RewriteBase' => '/',

Restart apache:

sudo systemctl restart apache2

and update your .htaccess file:

sudo -u www-data php /var/www/html/nextcloud/occ maintenance:update:htaccess

Hope that helps…

I did everything and then it started spitting out some internal errors, probably because I couldn’t update htaccess file. It said nextcloud doesn’t support php 8. But after restarting it seems to work fine and it did the trick. Thanks!

1 Like