How to setup subdomain to nextcloud at home, step by step?

Recently I did setup on my Raspberry Pi Nextcloud 15 and I really would like to put it under a subdomain like cloud.mydomain.me but can’t figure out how to accomplish it the right way.

My IP is public(so no DDNS issue), the domain is kept at namecheap.com and apache2 is used as web server, I would like to be able to load the normal index.html(at /var/www/html/) at mydomain.me meanwhile access the nextcloud instance at cloud.mydomain.me instead of mydomain.me/nextcloud(the default).
I’m also using certbot for Certificate generation, from what I understood I need to generate the certificate both for mydomain.me and cloud.mydomain.me but through the sudo certbot --apache the setup found only cloud.mydomain.me as an option.

What should I setup at Namecheap as host records?
What should I setup in the Apache config(000-default.conf)?
What should I setup in the config.php(at /var/www/html/nextcloud/config/)?
What should I setup to get certbot being able to see and generate the certs both for mydomain.me and cloud.mydomain.me?

I looked on the web for this type of guidance but they just skip on details on the setup of those parts that I can’t grasp because I’m a noob but still looking to accomplish this setup :slight_smile:

Ask me any more details if necessary.

PS: ports 80 and 443 to the Raspberry Pi local address are already open to the outside.

The output of my apache 000-default.conf:

<VirtualHost *:80>
        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]

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

<VirtualHost *:443>
    ServerName cloud.mydomain.me

    <IfModule mod_headers.c>
      Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload"
    </IfModule>
    SSLCertificateFile /etc/letsencrypt/live/cloud.mydomain.me/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/cloud.mydomain.me/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

The output of my config.php file in /var/www/html/nextcloud/config/:

<?php
$CONFIG = array (
  'instanceid' => 'REDACTED',
  'passwordsalt' => 'REDACTED',
  'secret' => 'REDACTED',
  'trusted_domains' =>
  array (
    0 => '192.168.1.226',#LAN IP Address
    1 => 'REDACTED',#public IP Address
    2 => 'cloud.mydomain.me'
  ),
  'datadirectory' => '/var/nextcloud/data',
  'dbtype' => 'sqlite3',
  'version' => '15.0.6.1',
  'overwrite.cli.url' => 'https://192.168.1.226/nextcloud',
  'htaccess.RewriteBase' => '/',
  'dbname' => 'cloud',
  'installed' => true,
  'updater.secret' => 'REDACTED',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
);

DNS records:

Hi, I would recommend to use another apache config file for your nextcloud site - then it will be easier to manage, and less risk of mixing up content between the sites. certbot will also be able to find and generate for both sites if you use different config files.

To do this, copy the 000-default.conf file to a new one, f.ex cloud.mydomain.me.conf. On debian/ubuntu type systems you should do that in the /etc/apache2/sites-available directory.
Change the ServerName in each config file so apache knows which config to use for the sites:

ServerName mydomain.me (in 000-default.conf)
ServerName cloud.mydomain.me (in cloud.mydomain.me.conf)

I would also recommend to make another DocumenRoot for the nextcloud site, to avoid mixup - fex /var/www/cloud.mydomain.me or /var/www/nextcloud (remember to move or reinstall the nextcloud files there as well)

You can add some more apache settings to make nextcloud work from the root (instead of /nextcloud) - see the install guide for further info on this and some other tips:

https://docs.nextcloud.com/server/15/admin_manual/installation/source_installation.html#apache-web-server-configuration

Remember to activate the new site by running: a2ensite cloud.mydomain.me

In DNS just add a cname for cloud.mydomain.me, pointing at you current dns name (or use A record pointing to the IP)

Now you can run certbot again and it should find both sites, if you got the configs correct.

Nextcloud will usually figure out most of the site settings automagically, but if needed you can use ‘overwrite.cli.url’ and some other related ones to make sure it knows which site URL to use. Don’t use the IP address anymore, as it will use the default apache config.

Hope that helps, good luck further on!

btw sqlite3 is very weak, use my/mariasql instead if you start using your cloud :slight_smile:

1 Like

Can you instruct how to propertly config the DNS? IP is already reserver for @ A record, should I create another A record to the same IP with “cloud” as Host? or with CNAME how to put the paramenters right?

Despite doing all of that successfully(except finishing DNS conf.), cloud.mydomain.me still redirects to the files(index.html) in the folder /var/www/html instead of /var/www/nextcloud. Do you know why?(Despite I cleaned the .conf of both from each other config paramenters)

Your DNS setup looks fine, it will work both with A and CNAME record. Use A record if you want to be 100% sure, but as long as both names resolves to the same IP when you look them up externally, they’re good.

Did you set DocumentRoot to /var/www/nextcloud in the cloud site conf?

You may also add a seperate apache logfile for the cloud site by adding this (path may be different for your distro) to it’s config file:

TransferLog /var/log/apache2/site-access.log

Then you will see if your requests hits the right site config. (I’ll recommend to have a seperate log file in any case, and use Customlog instead when you get it working)

If you don’t see any hits in that file, the requests ends up in the default config for some reason. Only thing I can think of is if you have the servers IP defined in the apache default config - this is not needed, so remove it if you have it.

Sry for late reply, but hope you figure it out.

1 Like

No, I didn’t set DocumentRoot, maybe it was the final piece of the puzzle.
I don’t mind for the late answers because I’m really much more appreciated of your help :slight_smile:
and I’m not in a rush and I have in plan to share the cloud with my family(but before that I need to get my hand on the technology at hand, secure it and optimize it for a production ready kind of service)

Back to the matter, I said “was” because now I moved to a Mini Intel PC as a server, much better as a server machine because the RaspberryPi kept crashing(totally unrealiable, in my experience).
I also decided also to move to a distro with a more up-to-date environment(OpenSUSE).
The latest Nextcloud version was nicely available/packaged and well set-up with all the dependencies.

Except now because I’m at the latest stable versions of apache2/php7 and a new environment with different default paths/user-agents, I’m a bit lost, look:

  1. (top left) the default path for web of apache2 is /srv/www/htdocs, and because it wasn’t installed manually I fear to move the nextcloud folder from there. Do you happen to know if it’s safe or should I ask to the OpenSUSE community?
  2. (top right) the apache2 folder is structured differently from the version on Debian. Before I had setted-up <VirtualHost>(and some templates can be found in the folder vhosts.d) in a custom cloud.mydomain.me.conf but now a default nextcloud.conf was generate upon installation in the conf.d folder, opened below.
  3. (bottom) it kind of resembles my custom .conf file except now it’s configuration looks like it’s based on the <Directory> tag (of which I don’t know the pros or cons against <VirtualHost>) and as such I don’t really know how to move to setup all the linking and redirection that I had before, for now I’ll backup the original, which BTW works great to provide http://mydomain.me/nextcloud, and work around getting back the old state of .conf but I would rather still will hear from you an approach or insight on this subject.

PS: Meanwhile I managed to setup an external hard disk at media/data with a folder chowned by wwwrun(different apache2 daemon/user on OpenSUSE) and setted up as data folder upon the first Nextcloud configuration webpage, quite proud of my achivement :slight_smile:

Hi, I like the spirit - it’s good to learn how things works, and it usually requires some trial and error :slight_smile:

I don’t know openSUSE in detail, but I know apache very well, and it’s pretty much the same configuration onall distros, even if the paths are different. So I don’t think it should be hard to get your current nextcloud setup moved into a virtual host. For reference, here’s the OpenSUSE documentation for apache vhost configuration:
https://doc.opensuse.org/documentation/leap/reference/html/book.opensuse.reference/cha.apache2.html#sec.apache2.configuration.manually.vhost

As you see, it’s pretty much identical to what you had in the previous config, just missing the nextcloud stuff. So I suggest that you first try to copy the contents of nextcloud.conf (but without the Alias directive) into a virtual host configuration - ie. enclose it inside <VirtualHost *:80> . The directory config doesn’t hurt, and you can keep the nextcloud files where they are for now.

Then add:

ServerName cloud.yourdomain
DocumentRoot /srv/www/htdocs/nextcloud

And optional but recommended:

ErrorLog /var/log/apache2/cloud.yourdomain-error.log
CustomLog /var/log/apache2/cloud.yourdomain-access.log common

I think that is all. so restart server and see if it works. Nextcloud is very flexible as well but if it should be confused by the new URL or domain, check the config/config.php file to see if something should be updated there.

If it works you can try to move the nextcloud folder elsewhere and remove the nextcloud.conf file.

btw it’s also recommended to setup a vhost config for your main site as well, in a similar way - then you have good control and logs for both the sites.

Good luck with your family cloud, and nice to hear you got the storage working :slight_smile: I’m using my own for family and private stuff as well, and got happy today when I managed to get full contact/calendar/tasks sync working against nextcloud - both with Thunderbird and Android (using the OpenSync app). Works very smooth so far :slight_smile:

1 Like

DirectoryRoot was indeed the final piece of puzzle. And after some trial and error I managed to restate the same configuration from the old installation and it worked :slight_smile:! Even with https and certbot.
And I also copy-pasted the same vhost for the main site and made the appropriate changes to configure it and apply https cert. through certbot too.(I just setup a basic redirection for now at that index.php)
Now I have this weird issue with some icons that don’t load, like:

Did you had such issue?

On the other side I started using DAVx5 on my Android to sync contacts and calendar from my Nextcloud… I also got rid of all of my google cloud sync. contacts and using exclusively the one from my nextcloud instance :slight_smile:

And also the scan from scan.nextcloud.com looks good for production :slight_smile:

Hi, great work! :slight_smile:

I’m not sure about the missing icons, haven’t had that issue but then I run my cloud with english menus and the default theme. It looks like you’re running with the dark-theme on your site? Might be some icons are missing from that theme - or maybe it it’s missing from the language version. Not sure really, but try to change to english or default theme just to see if it makes any difference.

But the rest looks good! :smiley:

2 Likes

It’s not about the language or theme, the outcome is the same. I’ll search for it here, and if I can’t find I’ll make a new post about.

I also had a lack of electricity and after the restart of the server nextcloud doesn’t work anymore :confused: I’ll open a new post for this too if I can’t find an answer(logs told something about intl, which I fixed but now I lack the nextcloud.log because I deleted it by mistake and it seems that it doesn’t want to reappear <.<

Just so you know, Nextcloud app is written in code. So when copy/paste an app some of it’s code does not properly indent. Hense the icons issue. A reinstall is preferable with config files and database backed up…

You should then be able to restore them to your new server. Allways have:
DocumentRoot: /var/www/nextcloud
ServerName: your_server_name (e.g. nextcloud.domain.tld)
ServerAlias: (e.g. www.nextcloud.domain.tld)

As above example your Apache conf file would be this:
/etc/apache2/sites-available/nextcloud.domain.tld.conf

And you would unzip nextcloud to:
/var/www

You can have as many vitual hosts as you wish under the same domain as long as hostname is setup as CNAME record pointing to hostname.domain.tld and A record is setup as domain pointing to your_ip_address or dynamic_ip_address(ddclient or script for DDNS)