Nextcloud redirects to cloud.nextcloud.com

Hi,

I installed Nextcloud on Debian 12.5. I was able to log in the first time and configure Nextcloud. I then set up and configured an SSL certificate with LetsEncrypt. That worked fine too.
However, when I try to get to the login page now, I’m getting redirected to cloud.nextcloud.com. I initially had that url in my nextcloud.conf file in the Redirect permanent line. I subsequently changed it to the correct url.

Here is my nextcloud.conf file (urls edited for security):

<VirtualHost *:80>
    ServerAdmin abc@xyz.com
    ServerName nextcloud.xyz.com
    Redirect permanent / https://nextcloud.xyz.com/
    DocumentRoot /var/www/html/nextcloud/
    <IfModule mod_headers.c>
      Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
    </IfModule>
        Alias /nextcloud "/var/www/html/nextcloud/"

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

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

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

RewriteEngine on
RewriteCond %{SERVER_NAME} =nextcloud.xyz.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

The output of your config.php file (edited for security):

<?php
$CONFIG = array (
  'instanceid' => 'whatever',
  'passwordsalt' => 'whatever',
  'secret' => 'whatever',
  'trusted_domains' =>
  array (
    0 => 'nextcloud.xyz.com',
  ),
  'datadirectory' => '/var/www/html/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '29.0.1.1',
  'overwrite.cli.url' => 'https://nextcloud.xyz.com',
  'overwriteprotocol' => 'https',
  'dbname' => 'nextclouddb',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloudusername',
  'dbpassword' => 'not for your eyes',
  'installed' => true,
);

Let me know if I can provide anything else to resolve this problem. I appreciate any help you can give me.

It shouldn’t be the source of your problem, however you have so many things in your VirtualHost, something like

<VirtualHost *:80>
	ServerName nextcloud.xyz.com
	RedirectMatch permanent ^/(.*)$ https://nextcloud.xyz.com/$1
</VirtualHost>

should be enough. I wouldn’t even set a DocumentRoot so it will be just impossible to reach Nextcloud without SSL (even if your redirect conditions fail).

(from the examples here: How To Create Temporary and Permanent Redirects with Apache | DigitalOcean).

Then I’d try to access via curl and check if the http request goes to https of your domain. Or if that already redirects to cloud.nextcloud.com, or if that appears later.

2 Likes

@tflidd Thanks for responding so quickly. Much appreciated.

Here is the curl out put I’m getting:

Not sure where the cloud.nextcloud.com is coming from. I looked all over the nextcloud directory and I couldn’t find it.

1 Like

First try the curl with http, not https. Just to check your first redirect.

Then the next step is to check the VHost for the https connection.

You can also check if anything in your config points to cloud.nextcloud.com:

grep -nri 'cloud.nextcloud.com' /etc

Maybe this is a silly question, but nextcloud.xyz.com isn’t the domain name you actually use for your Nextcloud, is it? I’m asking because this domain name redirects to nextcloud.xyz, where actually a Nextcloud is running :wink:

curl nextcloud.xyz.com
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Refresh" content="0;url=http://nextcloud.xyz/"/>
<title>301 Moved Permanently</title>
</head>
<body>
<script type="text/javascript">window.location.href="http://nextcloud.xyz/";</script>
</body>
</html>

Please also check the apache’s access_log, whether the request really arrives it.
btw.: Also check the other sites-enabled/*.conf files.
Is your nextcloud.conf enabled? - See sites-enabled folder.

@bb77 Correct, nextcloud.xyz.com in not the actual domain name for the site. It’s a placeholder for security.

I found the problem. I was working with the wrong conf file. I was always working on nextcloud.conf. When I set up SSL with LetsEncrypt it created the file nextcloud-le-ssl.conf. I fixed the redirection there.
All good now.

Thanks for everyone’s help. Really appreciate it.

1 Like

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.