Nextcloud Internal Server Error after connecting it to a domain

Nextcloud version (24.0.4.1)
Operating system and version (Ubuntu 22.04)
Apache2 (Apache 2.4.52)
PHP version (8.1.2)

The issue
I got a domain for Nextcloud in which I wanted to use to replace the standard IP address/nextcloud thing and also to access it from the internet so that I can finally rid myself of Google’s storage scam.

Well, apparently this plan went to nought because when I got the domain and configured Nextcloud to the domain(having already set up the server’s public ip to the domain), Nextcloud became inaccessible and as such could not work anymore. Initially nextcloud did work albeit I had to do “cloudserver.com/nextcloud”, but when I sought to change it by using Virtualhost, it just messed everything up and it just refuses to work at this point.

Is this the first time you’ve seen this error?
Yes

Steps to replicate it:
Not exactly sure what else it was but this is what I did prior.

  1. Add personal domain to the array within nextcloud’s php config file
  2. Change normal nextcloud config file in “sites available” within apache2 to use a virtualhost in order to have over the internet access into server. This was for the domain.

Nextcloud log in Admin > Logging:

{"reqId":"JYFhDVTBYmPhv6YSX1wd","level":2,"time":"2022-08-29T18:23:11+00:00","remoteAddr":"192.168.a.b","user":"--","app":"no app in context","method":"GET","url":"/nextcloud/","message":"Could not detect any host in http:///nextcloud/data/htaccesstest.txt","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36","version":"","data":[]}
{"reqId":"rsLWT33pWlhy8S6gYDRL","level":2,"time":"2022-08-30T15:32:47+00:00","remoteAddr":"192.168.c.d","user":"--","app":"no app in context","method":"GET","url":"/nextcloud/index.php/csrftoken","message":"Host 192.168.c.d was not connected to because it violates local access rules","userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0","version":"24.0.4.1","data":[]}
{"reqId":"LZSs5qL8CFJck36Bw0or","level":2,"time":"2022-08-30T16:41:46+00:00","remoteAddr":"192.168.c.d","user":"--","app":"no app in context","method":"GET","url":"/nextcloud/","message":"Host 192.168.c.d was not connected to because it violates local access rules","userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0","version":"24.0.4.1","data":[]}
{"reqId":"wGnMM0fYrecRsmgXdESF","level":2,"time":"2022-08-30T16:42:56+00:00","remoteAddr":"192.168.c.d","user":"--","app":"no app in context","method":"POST","url":"/nextcloud/index.php","message":"Host 192.168.c.d was not connected to because it violates local access rules","userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0","version":"24.0.4.1","data":[]}
{"reqId":"vqdMoqn6bbqiArUgs3rc","level":3,"time":"2022-08-30T17:33:07+00:00","remoteAddr":"192.168.a.b","user":"admin","app":"index","method":"GET","url":"/nextcloud/index.php/apps/theming/img/core/filetypes/image.svg?v=0","message":"Could not create folder","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36","version":"24.0.4.1","exception":{"Exception":"OCP\\Files\\NotPermittedException","Message":"Could not create folder","Code":0,"Trace":[{"file":"/var/www/nextcloud/lib/private/Files/AppData/AppData.php","line":156,"function":"newFolder","class":"OC\\Files\\Node\\Folder","type":"->"},{"file":"/var/www/nextcloud/apps/theming/lib/ImageManager.php","line":163,"function":"newFolder","class":"OC\\Files\\AppData\\AppData","type":"->"},{"file":"/var/www/nextcloud/apps/theming/lib/ImageManager.php","line":178,"function":"getCacheFolder","class":"OCA\\Theming\\ImageManager","type":"->"},{"file":"/var/www/nextcloud/apps/theming/lib/Controller/IconController.php","line":90,"function":"getCachedImage","class":"OCA\\Theming\\ImageManager","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":225,"function":"getThemedIcon","class":"OCA\\Theming\\Controller\\IconController","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":133,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/App.php","line":172,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/Route/Router.php","line":298,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/var/www/nextcloud/lib/base.php","line":1023,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/var/www/nextcloud/index.php","line":36,"function":"handleRequest","class":"OC","type":"::"}],"File":"/var/www/nextcloud/lib/private/Files/Node/Folder.php","Line":164,"CustomMessage":"--"}}
{"reqId":"As1oBqHiTchkpIZiFk8u","level":3,"time":"2022-08-30T17:48:04+00:00","remoteAddr":"192.168.c.d","user":"admin","app":"ocs_api","method":"POST","url":"/nextcloud/ocs/v2.php/cloud/users","message":"Unable to send the invitation mail to abcdef@yahoo.com","userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0","version":"24.0.4.1","exception":{"Exception":"Swift_TransportException","Message":"Connection could not be established with host 127.0.0.1 :stream_socket_client(): Unable to connect to 127.0.0.1:25 (Connection refused)","Code":0,"Trace":[{"function":"{closure}","class":"Swift_Transport_StreamBuffer","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php","line":264,"function":"stream_socket_client"},{"file":"/var/www/nextcloud/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php","line":58,"function":"establishSocketConnection","class":"Swift_Transport_StreamBuffer","type":"->"},{"file":"/var/www/nextcloud/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php","line":143,"function":"initialize","class":"Swift_Transport_StreamBuffer","type":"->"},{"file":"/var/www/nextcloud/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php","line":65,"function":"start","class":"Swift_Transport_AbstractSmtpTransport","type":"->"},{"file":"/var/www/nextcloud/lib/private/Mail/Mailer.php","line":195,"function":"send","class":"Swift_Mailer","type":"->"},{"file":"/var/www/nextcloud/apps/settings/lib/Mailer/NewUserMailHelper.php","line":184,"function":"send","class":"OC\\Mail\\Mailer","type":"->"},{"file":"/var/www/nextcloud/apps/provisioning_api/lib/Controller/UsersController.php","line":446,"function":"sendMail","class":"OCA\\Settings\\Mailer\\NewUserMailHelper","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":225,"function":"addUser","class":"OCA\\Provisioning_API\\Controller\\UsersController","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":133,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/App.php","line":172,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/Route/Router.php","line":298,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/var/www/nextcloud/ocs/v1.php","line":62,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/var/www/nextcloud/ocs/v2.php","line":23,"args":["/var/www/nextcloud/ocs/v1.php"],"function":"require_once"}],"File":"/var/www/nextcloud/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php","Line":261,"message":"Unable to send the invitation mail to abcdef@yahoo.com","exception":{},"CustomMessage":"Unable to send the invitation mail to abcdef@yahoo.com"}}
{"reqId":"TggBx8tqswfN3MXCXeQE","level":2,"time":"2022-08-30T17:51:00+00:00","remoteAddr":"192.168.c.d","user":"admin","app":"core","method":"POST","url":"/nextcloud/index.php/login/confirm","message":"Login failed: 'admin' (Remote IP: '192.168.c.d')","userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0","version":"24.0.4.1","data":{"app":"core"}}
{"reqId":"Asb3hxv6AyqThIJpeV0O","level":3,"time":"2022-09-01T11:19:29+00:00","remoteAddr":"192.168.a.b","user":"MarcusDStallion","app":"index","method":"GET","url":"/nextcloud/index.php/apps/theming/img/core/filetypes/text.svg?v=0","message":"Could not create folder","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36","version":"24.0.4.1","exception":{"Exception":"OCP\\Files\\NotPermittedException","Message":"Could not create folder","Code":0,"Trace":[{"file":"/var/www/nextcloud/lib/private/Files/AppData/AppData.php","line":156,"function":"newFolder","class":"OC\\Files\\Node\\Folder","type":"->"},{"file":"/var/www/nextcloud/apps/theming/lib/ImageManager.php","line":163,"function":"newFolder","class":"OC\\Files\\AppData\\AppData","type":"->"},{"file":"/var/www/nextcloud/apps/theming/lib/ImageManager.php","line":178,"function":"getCacheFolder","class":"OCA\\Theming\\ImageManager","type":"->"},{"file":"/var/www/nextcloud/apps/theming/lib/Controller/IconController.php","line":90,"function":"getCachedImage","class":"OCA\\Theming\\ImageManager","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":225,"function":"getThemedIcon","class":"OCA\\Theming\\Controller\\IconController","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":133,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/App.php","line":172,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/Route/Router.php","line":298,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/var/www/nextcloud/lib/base.php","line":1023,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/var/www/nextcloud/index.php","line":36,"function":"handleRequest","class":"OC","type":"::"}],"File":"/var/www/nextcloud/lib/private/Files/Node/Folder.php","Line":164,"CustomMessage":"--"}}

Config PHP File for Nextcloud

<?php
$CONFIG = array (
  'trusted_domains' =>
  array (
    0 => '192.168.x.y',
    1 => 'cloudserver.com',
    2 => 'a.b.c.d'
  ),
  'datadirectory' => '/media/joswole/Windows7/JoStorage/data',
  'dbtype' => 'mysql',
  'check_data_directory_permissions' => false,
  'version' => '24.0.4.1',
  'overwrite.cli.url' => 'http://192.168.x.y/nextcloud'
  'dbname' => 'clouddb',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'user',
  'dbpassword' => 'Nunyabusiness445',
  'installed' => true,
);

The output your Apache system log in /var/log/apache2/error.log:

[Sat Sep 03 00:00:12.381416 2022] [mpm_prefork:notice] [pid 1026] AH00163: Apache/2.4.52 (Ubuntu) OpenSSL/3.0.2 configured -- resuming normal operations
[Sat Sep 03 00:00:12.381443 2022] [core:notice] [pid 1026] AH00094: Command line: '/usr/sbin/apache2'

Your Apache configuration will be needed to troubleshoot this as that’s a likely cause of your problem.

This is my unedited 000-default config file from Apache’s sites available directory

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

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

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

However, if you are talking about the normal apache2.conf file instead of the 000 file, here it is

Had to put it in a pastebin since it was over 1000 words.

Update

I do not think Apache is the main cause of this. Why?

I set up DDNS to make sure that the domain points specifically to my server and nothing else. This seems to have alleviated that initial issue of my confused apache. Now typing in my domain leads straight to the Ubuntu apache landing page.

Using “/nextcloud” however does not work. I do not know why

What you describe is that it works by IP address but not with the virtual host. That’s an Apache configuration matter, which is why I suspect it.

However, the Apache site config you posted is one that’s 100% default… not one configured as a named virtual host, nor does it match what you described about using the /nextcloud path under the web root.

Is this really the site config you’re using for Nextcloud? Surely not…