Nextcloud Apache Redirections problems

Hi all !

I am having a hard time trying to setup the redirections mentionned in the admin panel :

  • /.well-known/webfinger ».
    « /.well-known/nodeinfo ».
    « /.well-known/caldav »
    « /.well-known/carddav »

I know there are other topics but I can’t get to understand or have those alerts removed.

I have done what’s in the doc without success (.htaccess part) https://docs.nextcloud.com/server/latest/admin_manual/issues/general_troubleshooting.html#service-discovery-label

##############

-I am running apache2 on a Debian 12 VPS.
-My nextcloud root is in /usr/share/nextcloud/
-PHP is 8.2

##############

-I have two virtualhosts, nextcloud.conf and nextcloud-ssl.conf

nextcloud.conf :

<VirtualHost *:80>
DocumentRoot /usr/share/nextcloud/
ServerName nextcloud.mydomain.com
Redirect permanent / https://nextcloud.mydomain.com/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /usr/share/nextcloud/>
Require all granted
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride ALL

<IfModule mod_dav.c>
Dav off
</IfModule>
#Order allow,deny
#Allow from all

</Directory>
</VirtualHost>

-In the doc they say to put Dav off I don’t know what it means. I have tried putting Dav on without success.

nextcloud-ssl.conf :

<IfModule mod_ssl.c>
 <VirtualHost *:443>
DocumentRoot /usr/share/nextcloud/
ServerName nextcloud.mydomain.com

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


<Directory /usr/share/nextcloud/>
 Options FollowSymLinks
 Options -Indexes +FollowSymLinks +MultiViews
 AllowOverride ALL
 Order allow,deny
 Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/nextcloud.error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/nextcloud.ssl_access.log combined

SSLEngine on
SSLCertificateFile /files_directory/fullchain.pem
SSLCertificateKeyFile /files_directory/privkey.pem

</VirtualHost>
</IfModule>

#############################

-The .htaccess which is in the /usr/share/nextcloud :

#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####

ErrorDocument 403 /index.php/error/403
ErrorDocument 404 /index.php/error/404

-If I write something in there, when I run the occ maintenance:update:htaccess, everything gets erased.

#############################

-Mod Rewrite is enabled :

a2query -m gives rewrite (enabled by site administrator)

##############################

I have tried adding this in the .htaccess but I think it’s not the way since the file gets erased when doing the occ command :


** RewriteEngine on**
** RewriteRule ^.well-known/carddav /nextcloud/remote.php/dav [R=301,L]**
** RewriteRule ^.well-known/caldav /nextcloud/remote.php/dav [R=301,L]**
** RewriteRule ^.well-known/webfinger /nextcloud/index.php/.well-known/webfinger [R=301,L]**
** RewriteRule ^.well-known/nodeinfo /nextcloud/index.php/.well-known/nodeinfo [R=301,L]**

-i have tried with and without the /nextcloud/ part, or adding /usr/share/ etc but nothing is ok.
-I have tried adding this directly in the nextcloud.conf and/or nextcloud-ssl.conf but nope. When doing that I have added the “/” before "^"

##############################

The /usr/share/nextcloud/config/config.php file :

<?php
$CONFIG = array (
  'instanceid' => 'blah',
  'passwordsalt' => 'blahblahblah',
  'secret' => 'blahblahblah',
  'trusted_domains' =>
  array (
    0 => 'nextcloud.mydomain.com',
  ),
  'datadirectory' => '/usr/share/nextcloud/data',
  'overwrite.cli.url' => 'https://nextcloud.mydomain.com/',
#  'htaccess.RewriteBase' => '/',
  'memcache.local' => '\OC\Memcache\APCu',
  'maintenance_window_start' => 1,
  'dbtype' => 'mysql',
  'version' => '28.0.4.1',
  'dbname' => 'blahblahblah',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'blahblahblah',
  'dbpassword' => 'blahblahblah',
  'installed' => true,
  'mail_smtpmode' => 'smtp',
  'mail_smtpsecure' => 'ssl',
  'mail_sendmailmode' => 'smtp',
  'mail_from_address' => 'blahblahblah',
  'mail_domain' => 'mydomain.com',
  'mail_smtphost' => 'blahblahblah',
  'mail_smtpport' => '465',
  'mail_smtpauth' => 1,
  'maintenance' => false,
  'mail_smtpname' => 'blahblahblah',
  'mail_smtppassword' => 'blahblahblah',
);

-The htaccess.RewriteBase is commented because it’s also creating display issues by the way. Basically images won’t display. Maybe the same problem ?

##############################

Also when I browse this url I get the message showing it is present :

https://example.com/remote.php/dav

This is the WebDAV interface. It can only be accessed by WebDAV clients such as the Nextcloud desktop sync client.

##############################

I also have these issues on the admin panel :

- core
	- INVALID_HASH
		- .htaccess
	- FILE_MISSING
		- .user.ini
		- 3rdparty/aws/aws-crt-php/gen_stub.php

-Maybe it is related ?

##############################

Well it is pretty much what I can say. I think I just don’t understand how redirections and .htaccess are working.
HTTPS is working and redirected automatically.

Thanks for your help :slight_smile:

Ok I have taken the .htaccess from nextcloud github and replaced mine. It contains a lot of stuff compared to my original one that contained almost nothing.

I find this directive which solved most issues :

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTP_USER_AGENT} DavClnt
  RewriteRule ^$ /remote.php/webdav/ [L,R=302]
  RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  RewriteRule ^\.well-known/carddav /remote.php/dav/ [R=301,L]
  RewriteRule ^\.well-known/caldav /remote.php/dav/ [R=301,L]
  RewriteRule ^remote/(.*) remote.php [QSA,L]
  RewriteRule ^(?:build|tests|config|lib|3rdparty|templates)/.* - [R=404,L]
  RewriteRule ^\.well-known/(?!acme-challenge|pki-validation) /index.php [QSA,L]
  RewriteRule ^ocm-provider/?$ index.php [QSA,L]
  RewriteRule ^(?:\.(?!well-known)|autotest|occ|issue|indie|db_|console).* - [R=404,L]
</IfModule>

I have tried adding lines for webfinger and nodeinfo without luck though.

#######################

I have almost no more error messages but still for webfinger and nodeinfo, and also regarding intergity check :


Results
=======
- core
	- INVALID_HASH
		- .htaccess
	- FILE_MISSING
		- .user.ini
		- 3rdparty/aws/aws-crt-php/gen_stub.php

Should I worry about those ?

1 Like