NextCloud Snap, NextCloud Office Not Starting because of http/https errors

  • Nextcloud version (eg, 20.0.5): Nextcloud Hub 4 (26.0.3)

  • Operating system and version (eg, Ubuntu 20.04): Ubuntu 22.04.2 LTS

  • Apache or nginx version (eg, Apache 2.4.25): Apache/2.4.52 (Ubuntu)

  • PHP version (eg, 7.4): PHP 8.1.2-1ubuntu2.13 (cli), Zend Engine v4.1.2

  • Is this the first time you’ve seen this error? (Y/N): N

Steps to replicate it:

  1. Install NC snap.
  2. Configure Apache to work with snap in parallel to existing webserver.
  3. Install Nextcloud Office.
  4. Watch the blank screen when opening an office document.

The output of your Nextcloud log in Admin > Logging:


Hi everyone. Thanks in advance for all your help. I’ve been struggling for weeks trying to get this working for our small organization. I’m trying to run Nextcloud on a VPS-like configuration (I installed Ubuntu Server LTS on it). I have an Apache webserver running a WordPress site conventionally. After many failures trying a regular install of Nextcloud, I tried Docker and that had problems, and now I’m using the Snap version of Nextcloud which has made significant improvements. At least Nextcloud runs now. Unfortunately this is all beyond my level of knowledge and none of the guides online seem to address the issue in a way I can understand.

But I cannot get Nextcloud Office working, which is an absolute requirement.

The Problem:
When an office document is clicked on for editing, the Office editor never appears. An inspection of the document reveals a possible root cause of mixed domains being served by NextCloud Office (http) even though the main part of Nextcloud is https.

Depending on the random thing I try, I get the following general categories of problems in the browser’s console which results in a black screen when loading any office document:

A) xhr.js:220 GET https://nextcloud.foo.com/index.php/apps/files/api/v1/stats net::ERR_TOO_MANY_REDIRECTS

B) ConsoleLogger.js:59 [ERROR] files: Could not refresh storage stats {app: ‘files’, uid: ‘trogdor’, level: 2, error: i}

C) core-common.js?v=436578ce-1:2 Refused to connect to ‘http://nextcloud.foo.com/extra-apps/richdocumentscode/proxy.php?status’ because it violates the following Content Security Policy directive: “connect-src ‘self’”.

D) core-common.js?v=436578ce-1:2 Mixed Content: The page at ‘https://nextcloud.foo.com/index.php/apps/files/?dir=/Board%20Documents&openfile=2305’ was loaded over a secure connection, but contains a form that targets an insecure endpoint ‘http://nextcloud.foo.com/extra-apps/richdocumentscode/proxy.php?req=/browser/10deb70/cool.html?WOPISrc=https%3A%2F%2Fnextcloud.foo.com%2Findex.php%2Fapps%2Frichdocuments%2Fwopi%2Ffiles%2F2305_ocy3e1cpaznr&title=Trogdor%20notes%20(do%20not%20share).odt&lang=en&closebutton=1&revisionhistory=1’. This endpoint should be made available over a secure connection.

Computer Configuration

    Server
        Apache web server
            --> Wordpress
            --> Nextcloud Snap

Server IP & domain

Domain and IP have been changed for privacy but:

Note: Apache / MySQL / PHP WordPress site running on https://foo.com

Ports

Snap is configured to use port 8080 and 8443, since it would otherwise conflict with Apache.

  • sudo snap set nextcloud ports.http=8080
  • sudo snap set nextcloud ports.https=8443

Trusted Proxy

sudo nextcloud.occ config:system:set trusted_proxies 1 --value=123.123.123.123

Certificates

  • Using proxy to get SSL certificates.

/etc/apache2/sites-available/nextcloud.foo.com.conf

<VirtualHost *:80>
        Header always set Strict-Transport-Security "max-age=31536000; includeS>
        ServerName nextcloud.foo.com
        ErrorLog ${APACHE_LOG_DIR}/nextcloud-error.log
        CustomLog ${APACHE_LOG_DIR}/nextcloud-access.log combined
        ProxyPreserveHost On
        ProxyPass / http://127.0.0.1:8080/
        ProxyPassReverse / http://127.0.0.1:8080/
        RewriteEngine on
        #RewriteCond %{SERVER_NAME} =nextcloud.foo.com
        #RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanen>
        RewriteRule ^/\.well-known/carddav http://%{SERVER_NAME}/remote.php/dav>
        RewriteRule ^/\.well-known/caldav http://%{SERVER_NAME}/remote.php/dav/
</VirtualHost>

/etc/apache2/sites-available/nextcloud.foo.com-le-ssl.conf

<VirtualHost *:443>
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomain>
        ServerName nextcloud.foo.com
        SSLProxyEngine On
        SSLProxyVerify None
        SSLProxyCheckPeerCN Off
        SSLProxyCheckPeerExpire Off
        SSLProxyCheckPeerName off
        SSLVerifyClient none
        ProxyRequests Off
        ProxyPreserveHost On
        SSLCertificateFile /etc/letsencrypt/live/nextcloud.foo.com/full>
        SSLCertificateKeyFile /etc/letsencrypt/live/nextcloud.foo.com/p>
        # listens on ports 8080 and 8443
        ProxyPass / http://nextcloud.foo.com:8080/
            #ProxyPass / http://127.0.0.1:8080/
        ProxyPassReverse / https://nextcloud.foo.com/
            #ProxyPassReverse / http://127.0.0.1/
        RewriteEngine On
        RewriteRule ^/\.well-known/carddav https://%{SERVER_NAME}/remote.php/da>
        RewriteRule ^/\.well-known/caldav https://%{SERVER_NAME}/remote.php/dav>
</VirtualHost>

/var/snap/nextcloud/current/nextcloud/config/config.php

<?php
$CONFIG = array (
  'apps_paths' =>
  array (
    0 =>
    array (
      'path' => '/snap/nextcloud/current/htdocs/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 =>
    array (
      'path' => '/var/snap/nextcloud/current/nextcloud/extra-apps',
      'url' => '/extra-apps',
      'writable' => true,
    ),
  ),
  'supportedDatabases' =>
  array (
    0 => 'mysql',
  ),
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'redis' =>
  array (
    'host' => '/tmp/sockets/redis.sock',
    'port' => 0,
  ),
  'log_type' => 'file',
  'logfile' => '/var/snap/nextcloud/current/logs/nextcloud.log',
  'logfilemode' => 416,
  'passwordsalt' => 'xxxxxxxxxxxxxxx',
  'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
  'trusted_domains' =>
  array (
    0 => 'localhost',
    1 => 'nextcloud.foo.com',
  ),
  'datadirectory' => '/var/snap/nextcloud/common/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '26.0.3.2',
  'overwrite.cli.url' => 'http://localhost',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost:/tmp/sockets/mysql.sock',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'xxxxxxxxxxxxxxxxxxxxxxx>
  'installed' => true,
  'instanceid' => 'ocy3e1cpaznr',
  'maintenance' => false,
  'mail_smtpmode' => 'smtp',
  'mail_smtpsecure' => 'ssl',
  'mail_sendmailmode' => 'smtp',
  'mail_from_address' => 'nextcloud',
  'mail_domain' => 'foo.com',
  'mail_smtphost' => 'mail.foo.com',
  'mail_smtpport' => '465',
  'mail_smtpauth' => 1,
  'default_phone_region' => 'US',
  'overwritehost' => 'nextcloud.foo.com',
  'overwriteprotocol' => 'https',
  'mail_smtpname' => 'nextcloud@foo.com',
  'mail_smtppassword' => 'xxxxxxxxxxxxxxxxxxxx',
  'trusted_proxies' =>
  array (
    1 => '123.123.123.123',
  ),
);

EDIT: cross referencing to a similar thread… possibly the exact same problem. Nextcloud Office showing only Loading - #15 by Adam42

1 Like

This completely solved it for me!

SOLUTION: https://help.nextcloud.com/t/collabora-built-in-code-reverse-proxy-ssl-enable-and-ssl-termination/161943

<IfModule mod_ssl.c>
<VirtualHost *:443>
 ServerName www.(MYDOMAIN)
 ProxyPreserveHost On 
 DocumentRoot /var/www/html
 ProxyPass /.well-known !
 ProxyPass / http://192.168.2.31:80/ flushpackets=on
 ProxyPassReverse / http://192.168.2.31:80/
 LimitRequestBody 0

 RequestHeader set X-Forwarded-SSL "1"
 RequestHeader set X-Forwarded-Proto "https" env=HTTPS

 <IfModule mod_headers.c>
   RewriteEngine On
   Header always set Strict-Transport-Security "max-age=15768000; preload"
   Redirect 301 /.well-known/carddav https://www.(MYDOMAIN)/remote.php/dav
   Redirect 301 /.well-known/caldav https://www.(MYDOMAIN)/remote.php/dav
   Redirect 301 /.well-known/webfinger https://www.(MYDOMAIN)/index.php/.well-known/webfinger
   Redirect 301 /.well-known/nodeinfo https://www.(MYDOMAIN)/index.php/.well-known/nodeinfo
 </IfModule>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/(MYDOMAIN)-0003/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/(MYDOMAIN)-0003/privkey.pem
</VirtualHost>
</IfModule>

What’s the key difference then? (Sorry apache xml config files are not my strong point!)

I don’t really know. I just blindly took it from the referenced forum. Someone else figured it out.