Can't post comments when connected via Cloudflare but can when connecting by LAN IP address of container

Nextcloud version: 27.1.2
Operating system and version: Proxmox>LXC>turnkeylinux nextcloud (Debian 11)
Apache or nginx version: Apache version 2.4.56
PHP version: 8.1.17

The issue you are facing:

When I connect to my Nextcloud instance via my domain name, which uses Cloudflare DNS, and I try to post a comment, either on a file or in response to an announcement from the Announcement Center app. I am unable to do so. But when I connect directly to the LAN IP address of the LXC container where Nextcloud is running, I am able to post comments.

When I try to post the comment, I get a error popup that says An error occurred while trying to create the comment but nothing appears in the logs. THe odd thing is, is that I’m able to upload, create, and delete files just fine… I just can’t comment on them.

It make me think that it’s a permissions issue of some kind but everying in /var/www/nextcloud is owned by www-data:www-data

I’ve tried changing various settings on Cloudflare, including turning the following off and / or on:

  • Rocket Loader
  • Brotli
  • Minify
  • CNAME proxy setting

The behaviour remains the same.

I had also encountered an issue where I was unable to login when accessing Nextcloud via my domain name but adding the trusted_proxies seen below in my config.php, and clearing the cookies for my domain name, seams to have fixed that issue. But I’m wondering whether this new issue with comments might be related in some way?

I should also note that my Nextcloud instance is currently for LAN use only. So I have HAProxy setup on my pfSense system, to only listen to and redirect to my Nextcloud server to addresses within my LAN. I am a noob when it comes to HAProxy though, so perhaps there’s an issue with the frontend that handles my Nextcloud server?

The output of your config.php file:

Anything with the word “example” or “>snip<” has been redacted for privacy.

root@nextcloud .../nextcloud/config# cat config.php
<?php
$CONFIG = array (
  'passwordsalt' => '>snip<',
  'secret' => '>snip<',
  'trusted_domains' => 
  array (
    0 => 'localhost',
    1 => 'cloud.example.com',
    2 => 'LAN IP Example',
  ),
  'trusted_proxies' => 
  array (
    0 => '172.67.223.168', #NOTE this is one of the Cloudflare IP addresses that my domain is routed through. 
    1 => '104.21.38.147', #NOTE and this is the other Cloudflare IP.
    2 => 'Virtual IP Example',
  ),
  'datadirectory' => '/var/www/nextcloud-data',
  'dbtype' => 'mysql',
  'version' => '27.1.2.1',
  'overwrite.cli.url' => 'http://localhost',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => '>snip<',
  'installed' => true,
  'instanceid' => '>snip<',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/var/run/redis/redis.sock',
    'port' => 0,
    'timeout' => 0.0,
  ),
  'filelocking.enabled' => true,
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'updater.secret' => '>snip<',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'default_phone_region' => '>snip<',
  'mail_smtpmode' => 'smtp',
  'mail_smtphost' => 'smtp.gmail.com',
  'mail_sendmailmode' => 'smtp',
  'mail_smtpport' => '465',
  'mail_from_address' => '>snip<',
  'mail_domain' => 'gmail.com',
  'mail_smtpsecure' => 'ssl',
  'mail_smtpauth' => 1,
  'mail_smtpname' => '>snip<',
  'mail_smtppassword' => '>snip<',

##### custom added settings

  'default_locale' => '>snip<',
  'default_phone_region' => '>snip<',
  'default_language' => '>snip<',
  'allow_user_to_change_display_name' => true,


);

NOTE: In regards to the various other logs that the default comment template recommends attaching, including the Web UI’s logging section, I looked through them myself but there were no entries with timestamps anywhere near the time that the issues occur (not even within the same couple of hours). So I haven’t included them but I can upon request.

EDIT: I forgot to mention that there is also no issues showing in “Overiew” of the admin user’s settings, and when I run the occ integrity:check-core command, no issues are found.


UPDATE: I’ve tried more CLoudflare settings, including disabling more settings, clearing and / or bypassing the Cloudflare Cache, enabling developer mode for my domain, and I completely disabled Cloudlfare for my domain. Nothing made a difference.

I did make a bit of a discovery though…

After playing around with Firefox’s page inspection tools (which I know pretty much nothing about), I found that I was getting console errors when I’d either hit Enter or click the submission arrow on a comment I’d just written. The comment would not post but I would get one or more “Source map error: Error: NetworkError when attempting to fetch resource.” errors popping up in the console related to the /var/www/nextcloud/dist/core-common.js and the /var/www/nextcloud/dist/comments-common.js files. These errors appear when connecting via my domain name but not via LAN.

To complicate matters… the issues I was having with logging in when connecting via my domain name, have reappeared. Interestingly, I get the same errors in the Firefox console. So I’m guessing then issues may be related.

But wait, there’s more!

I have actually somehow managed to post a comment by just clicking on a bunch of random things in the Firefox Debugger… I just can’t remember what I clicked! I’m pretty sure it went along these lines.

  1. tried to post a comment, which made an error pop up in the Firefox Console.
  2. I clicked on the error, which opened the Debugger tab.
  3. I then clicked on one of the entries related to said error, in the Debugger tab.
  4. At this point, I’m pretty sure the page loaded something else in my peripheral vision but I’m really note sure.
  5. The comment posted.

I’ve tried recreating my steps to post a comment but now I can’t even log back in.

I also found out that I could edit existing comments (that I posted when connected directly to the LAN IP), even though I can’t post new comments.