Internal server error when using subdomain

Hi!

Preface: Sorry about the spaces and commas in the links, the forum won’t let me add links to the post because I’m a new user (strange rule, if you ask me…)

I’m using NextCloud 14 with Apache2 webserver. If I’m trying to access NextCloud through the default address (https: // mydomain,com/nextcloud), everything is fine.
But I want to make a change and access it through a subdomain (https: // nextcloud,mydomain,com/). I’ve created the subdomain and the Apache virtual host and it seems to work, but NextCloud is unable to stomach the fact that it’s being accessed through the subdomain and gives “Internal Server Error” at the login page (https: // nextcloud,mydomain,com/login).

Do I need to make some configuration changes in NextCloud itself to make it run from the subdomain?

Here is my /var/www/html/nextcloud/config/config.php:

<?php
$CONFIG = array (
  'instanceid' => 'EDITED',
  'passwordsalt' => 'EDITED',
  'secret' => 'EDITED',
  'trusted_domains' =>
  array (
    0 => 'localhost',
    1 => 'mydomain.com',
    2 => 'nextcloud.mydomain.com',
  ),
  'datadirectory' => '/path/nextcloud',
  'dbtype' => 'mysql',
  'version' => '14.0.3.0',
  'overwrite.cli.url' => 'https: // mydomain,com/ nextcloud',
  'htaccess.RewriteBase' => '/nextcloud',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost:443',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'EDITED',
  'dbpassword' => 'EDITED',
  'installed' => true,
  'mail_smtpmode' => 'smtp',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_from_address' => 'NextCloud',
  'mail_domain' => 'mydomain.com',
  'mail_smtphost' => 'smtp.gmail.com',
  'mail_smtpport' => '587',
  'mail_smtpname' => 'EDITED',
  'mail_smtppassword' => 'EDITED',
  'mail_smtpsecure' => 'tls',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'maintenance' => false,
);

Also here is the Apache virtual host config:

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

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

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

       SetEnv HOME /var/www/html/nextcloud
       SetEnv HTTP_HOME /var/www/html/nextcloud
</Directory>

Redirect 301 /.well-known/carddav https: // mydomain,com/nextcloud/remote.php/dav
Redirect 301 /.well-known/caldav https: // mydomain,com/nextcloud/remote.php/dav

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

        Redirect / https: // nextcloud,mydomain,com/

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

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin admin@mydomain.com
        ServerName nextcloud.mydomain.com
        DocumentRoot /var/www/html/nextcloud

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

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

        SSLCertificateFile /path/fullchain.pem
        SSLCertificateKeyFile /path/privkey.pem
</VirtualHost>
</IfModule>

I’m using Ubuntu 18.04.

Is it a typo that your redirect line is

 Redirect / https: // nextcloud,mydomain,com/

? this should be periods, not commas.

And the Directory section should be inside the

<VirtualHost *:443>

section. So the file would only contain two VirtualHost sections, nothing outside.

In the config.php, the overwrite.cli.url should read

'overwrite.cli.url' => 'https://nextcloud.mydomain.com/',
'htaccess.RewriteBase' => '/',

The port number in dbhost should refer the mysql port 3306, not the https port 443.

That’s what I saw at first glance, maybe there is more… tell us your progress.

Thank you, eehmke!

The commas instead of periods are just to fool the forum editor, because I’m a new user and it won’t let me post links. That’s a weird rule on a technical web-related forum where people need to post links to explain things… so I replaced the periods with commas :slight_smile:

I’ve made all the changes you suggested:

  • moving the Directory section into the virtual host (but that’s just to have a nice config, I know for a fact that it was not a problem)
  • correcting the overwrite.cli.url in the Nextcloud config
  • correcting the htaccess.RewriteBase in the nextcloud config
  • correcting the dbhost port in the nextcloud config

Unfortunately this may have fixed some other minor stuff that I did not know about, but it did not fix the main probelm, I still get the “Internal server error”.

If I tail the nextcloud.log, I see thing in it like the following:

{“reqId”:“dmkLaze7YWDfDKkhMlj2”,“level”:3,“time”:“2018-10-31T09:27:08+00:00”,“remoteAddr”:“188.213.217.254”,“user”:"–",“app”:“index”,“method”:“GET”,“url”:"/login",“message”:{“Exception”:“Exception”,“Message”:“The requested uri(/login) cannot be processed by the script ‘/nextcloud/index.php’)”,“Code”:0,“Trace”:[{“file”:"/var/www/html/nextcloud/lib/base.php",“line”:930,“function”:“getRawPathInfo”,“class”:“OC\AppFramework\Http\Request”,“type”:"->",“args”:[]},{“file”:"/var/www/html/nextcloud/index.php",“line”:42,“function”:“handleRequest”,“class”:“OC”,“type”:"::",“args”:[]}],“File”:"/var/www/html/nextcloud/lib/private/AppFramework/Http/Request.php",“Line”:742,“CustomMessage”:"–"},“userAgent”:“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36”,“version”:“14.0.3.0”}

The question is what are all those “/” slash combinations in the paths. IS that simply because it’s escaping slashes in the stringsa using a backslash or do I have some weird problem which introduces an unnecessary slash or backslash into file paths?

I just noticed that the forum editor removed all those strange “\ /” (no space between) pairs form my post that I see in all file paths in the nextcloud.log. In the log all file paths are not delimited by a simple slash, but by a pair or backslash and slash, like this: “\ /var\ /www\ /html\ /nextcloud\ /lib\ /base.php” (without the spaces, I just added those so that the editor won’t remove the "\ / " pairs.

Do you have an apache error log?

No, Apache shows no errors in the log.

But I’ve figured it out by looking at the /var/www/html/nextcloud/config/config.sample.php example config file and readin the comment above the htaccess.RewriteBase setting. It says that after modifying this setting, you need to run the following command: “sudo -u www-data php occ maintenance:update:htaccess”. And so it is! That fixed it for me after applying the changes suggested by you, eehmke. So yes, your changes were needed but also this updating command had to be executed. Note that if you run Apache under a different user, not www-data, then you need to use that user to execute this updating command.

Thank you very much for your help! I could not have figured it out without your input. I appreciate it!

1 Like