Help setting up Apache2 site configuration to pointing to subdomain

I’m new to NextCloud and has just installed it on my own server. I really like it but I have problems setting up the nextcloud.conf (Apache2 Site configuration) to directing to my subdomain: https://cloud.mydomain.net

I’m also new to Apache so i’m sorry if it is a simple Apache configuration question. I have searched online but can’t find a solution that works for me.

Here is my setup:

  • Running my nextcloud server on a Debian 10 machine
  • The nextcloud folder is located at /var/www/html/nextcloud

My nextcloud.conf contains this

<VirtualHost *:80>
       ServerName cloud.mydomain.net
       Redirect permanent / https://cloud.mydomain.net
    </VirtualHost>

    <VirtualHost *:443>
      ServerAdmin admin@example.com
      DocumentRoot /var/www/html/nextcloud/
      ServerName cloud.mydomain.net

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

      <Directory /var/www/html/nextcloud/>
        Options +FollowSymlinks
        AllowOverride All

       <IfModule mod_headers.c>
         Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload"
       </IfModule>

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

       SetEnv HOME /var/www/html/nextcloud
       SetEnv HTTP_HOME /var/www/html/nextcloud

      </Directory>
    </VirtualHost>

I have no problems reaching the nextcloud webinterface on https://cloud.mydomain.net/nextcloud/. But what should I do to access it on https://cloud.mydomain.net?

What do I do wrong? Is it my Apache site configuration file that is setup wrong? Or is it something else?

Again, sorry if it is a rudimental issue but all help is highly appreciated.This text will be hidden

What do you get when you laod https://cloud.mydomain.net?
If I get a servername/domain/subdomain for the nextcloud itself (what i highly recommend) then i leave the Alias line out.

Thanks for your reply.

I get redirected to: https://cloud.mydomain.net/login and it says:

## Internal Server Error

The server was unable to complete your request.
If this happens again, please send the technical details below to the server administrator.
More details can be found in the server log.

If I remove the Alias line. I get a 500 Internal server Error page.

Then I’d recommend you to enable the log:

ErrorLog ${APACHE_LOG_DIR}/nextcloud_error.log
CustomLog ${APACHE_LOG_DIR}/nextcloud_access.log combined

I put them between ServerName and Alias, but I dont think the place realy matters.
Then you can read the errorlog sudo less /var/log/apache2/nextcloud_error.log

Please share the content with us - perhaps even with the solution to it :wink:

Thanks for the suggestion.

I have added the lines between ServerName and Alias. However, the nextcloud_error.log is empty.

BTW - should I have placed my nextcloud folder in /var/www/ instead of /var/www/html/?

Okay, now the error log contains:

[Sun Jun 07 13:02:21.573603 2020] [core:error] [pid 20230] [client 192.168.1.1:22435] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

[Sun Jun 07 13:02:23.803628 2020] [core:error] [pid 20231] [client 192.168.1.1:1500] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

[Sun Jun 07 13:02:31.678932 2020] [core:error] [pid 20233] [client 192.168.1.1:58831] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

I don’t know if that helps?

Ah yes. I havent recognize that in your conifg.

I’d recommend to put nextcloud in /var/www/nextcloud directly and chang the nextcloud.conf file. You can then disable the site 000-default.conf by sudo a2dissite 000-default.conf. That site is in the folder /var/www/html.

Change your redirect in the http (*:80) section.

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} !^/.well-known
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [NC,NE,R=permanent,L]

The line with .well-known is to allow certbot automatic renewals.

Once your site is working you might want to setup php-fpm, which will give a good performance boost.

Okay, can I just use the mv -R command or will the settings in the nextcloud setup be broke if I manually move the folder?

Thanks for the suggestion. I have inserted in the *:80 section.

I’d recommend you to cange a line in /var/www/nextcloud/config/config.php

Thanks for your help.

Now I have:

  • Moved the folder “sudo mv /var/www/html/nextcloud /var/www/nextcloud”
  • Changed the path my nextcloud.conf to /var/www/nextcloud
  • Disabled the default site
  • Set the parameters in the nextcloud config to: ‘overwrite.cli.url’ => ‘https://cloud.mydomain.net/’,
    ‘htaccess.RewriteBase’ => ‘/’,
  • Reloaded Apache “sudo systemctl reload apache2”

However, it still doesn’t work. I get the internal error message. And if I go to https://cloud.mydomain.net/nextcloud is works.

I think I solved it.

I ran the sudo -u www-data php /var/www/nextcloud/occ maintenance:update:htaccess and now it works.

I guess that I should have ran that update:htaccess before?

But thanks for Your replies and help with solving the issue.

1 Like

I’m happy to hear it’s solved.