Question - Apache Nextcloud.conf setup standard vs virtual

During the install document it describes setting up the nextcloud.conf. There are two options.

A standard and a virtual option.
Could someone explain the differences, when you would use one over the other?

By standard I mean this conf file configuration as per the manual.

Alias /nextcloud "/var/www/nextcloud/"

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

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

Hi @exup

The so-called standard configuration is actually not really β€œthe standard” these days. I would recommend using a VirtualHosts based configuration with subdomains.

Standard installation in this context means, that you use the default or standard webroot of the web server and then install additional applications/websites in subdirectories of this web server. That is why it is also called directory based. You would then access your sites as follows:

yourdomain.com (webroot, main website)
yourdomain.com/nextcloud
yourdomain.com/webapp2
yourdomain.com/website2

With the VirtualHosts variant, you create one or multiple virtual web servers (VirtualHosts), which are then accessible induvidually via their subdomains:

nextcloud.yourdomain.com
www.yourdomain.com
webapp2.yourdomain.com
website2.yourdomain.com

Hope that helps.

I also always would configure a virtual host. Look here .

OK thanks for clarifying that.
Is it also why its not so well recommended to install the NC inside the webroot which I take the webroot to be β€œ/var/www/” and instead install in the sub folder β€œ/var/www/html/”

If you use subdomains every site should be placed in separate folders. Each of these folders can then be defined as webroot in the respective VirtualHost configuration. Whether you create these folders in /var/www/ or var/www/html or somewhere else in the file structure is basically irrelevant.

The problem with /var/www/ is, that there are already predifined directives for this location in the global apache.conf file. Therfore it is better to use a dedicated folder like /var/www/nextcloud as webroot for Nextcloud and add the directives that need to differ from the ones predifined in the apache.conf, to the VirtualHost configuration file for Nextcloud. Otherwise the directives from the apache.conf will be used. You should also disable the default Apache VirtualHost, which points to /var/www/html.

With that in mind it seems not to be mentioned in the NC documentation to make any changes to that file. In fact I had an issue where caldav redirection errors came up in NC admin page. The only fix I found was to add redirects to the apache2/sites-available/NC.conf file. (Shown below) Again this was not mentioned at all in the NC install guide for Ubuntu LTS example. The last two lines I added below.

Alias /nextcloud "/var/www/html/nextcloud/" 

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

 <IfModule mod_dav.c> 
   Dav off  
 </IfModule> 
</Directory>
    Redirect 301 /.well-known/carddav /nextcloud/remote.php/dav 
      Redirect 301 /.well-known/caldav /nextcloud/remote.php/dav
   Satisfy Any

This is the apache2.conf which I have not edited. Note someone suggested to make it AllowOverride All but it did not fix the error.

Question what should have been the reason for the CalvDav and cardDav redirect errors? And what is the correct fix.

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

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

If you use a seperate VirtualHost like apache2/sites-available/NC.conf it should look something like that:


<VirtualHost *:80>
     ServerAdmin admin@example.com
     DocumentRoot /var/www/html/nextcloud/
     ServerName nextcloud.example.com

     <Directory /var/www/html/nextcloud/>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
          <IfModule mod_dav.c>
            Dav off
          </IfModule>
        SetEnv HOME /var/www/html/nextcloud
        SetEnv HTTP_HOME /var/www/html/nextcloud
     </Directory>

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

</VirtualHost>

You then have to enable the VirtualHost with sudo a2ensite NC.conf. And disable the 001-default.conf with a2dissite 001-default. And you have to restart apache with sudo systemctl restart apache2 to apply the changes.

You do not need the Alias directive at all and you do not need any redirects for webdav, if .htaccess is active, which should be the case because of the AllowOveride all directive.

Maybe you have to upgrade regenerate your .htaccess file, after you made the changes to the webserver config.

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

I will need to do a fresh install, as my current working NC instance is about to die due to hardware. So I am reviewing the install process in details and trying to understand the building blocks so your answers are very helpful. I am always a bit mindful of just trying things suggested in forums. What you say does line up closely with the NC official docs.

Only one last thing I see you add the two lines which was not mentioned in the apache setup guide.

may I ask where that is mentioned/section in the NC docs, or is this something that is just learnt?

To be honest i’m not a 100% sure if they strictly needed in the context of Nextcloud. They seem not to be mentioned in the official docs. But they are included in nearly every guide and they seem do at least no harm :wink:

1 Like