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