Nextcloud: trusted domain "127.0.0.1" tried to access using "domain" as host

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 20.0.5): 24.0.3.2
Operating system and version (eg, Ubuntu 20.04): AlmaLinux 8
Apache or nginx version (eg, Apache 2.4.25): nginx/1.14.1
PHP version (eg, 7.4): latest (Unsure, using snap)

The issue you are facing:

I’ve configured nextcloud and set up the trusted domains and proxies (I am running the NC snap behind nginx) but when trying to visit the web interface, I get this error in the logs:

{"reqId":"Caefij5XzylSuzhP4Dx1","level":2,"time":"2022-08-13T21:57:14+00:00","remoteAddr":"127.0.0.1","user":"--","app":"core","method":"GET","url":"/","message":"Trusted domain error. \"127.0.0.1\" tried to access using \"cloud.the-gdn.net\" as host.","userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0","version":"24.0.3.2","data":{"app":"core"}}

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

Steps to replicate it:

Unsure, but I (think) this is how to reproduce it:

  1. Install the nextcloud snap and change its HTTP/HTTPS ports. Ensure your running behind the Nginx reverse proxy.
  2. Set trusted_domains/trusted_proxies appropriately.
  3. Try to access nextcloud.

My nginx configuration looks like this:

server {
    listen                  443 ssl http2;
    listen                  [::]:443 ssl http2;
    server_name             cloud.the-gdn.net;
    root                    /dev/null;
    # SSL
    ssl_certificate         /etc/letsencrypt/live/cloud.the-gdn.net/fullchain.pem;
    ssl_certificate_key     /etc/letsencrypt/live/cloud.the-gdn.net/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/cloud.the-gdn.net/chain.pem;
# Logging
error_log /var/log/nginx/cloud.the-gdn.net.error.log warn;
access_log /var/log/nginx/cloud.the-gdn.net.access.log;
    location / {
    proxy_set_header X-Forwarded-For $proxy_protocol_addr; # To forward the original client's IP address 
    proxy_set_header X-Forwarded-Proto $scheme; # to forward the  original protocol (HTTP or HTTPS)
    proxy_set_header Host $host; # to forward the original host requested by the client
proxy_hide_header X-Content-Type-Options;
add_header X-Content-Type-Options "" always;
proxy_pass https://127.0.0.1:11112;
}
# DAV setup
location /.well-known/carddav {
    return 301 $scheme://$host/remote.php/dav;
}
location /.well-known/caldav {
    return 301 $scheme://$host/remote.php/dav;
}
# Additional config
    include nginxconfig.io/general.conf;
}
# HTTP redirect
server {
    listen      80;
    listen      [::]:80;
    server_name cloud.the-gdn.net;
    include     nginxconfig.io/letsencrypt.conf;
    location / {
        return 301 https://the-gdn.net$request_uri;
    }
}

The output of your Nextcloud log in Admin > Logging:

Unable to retrieve

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?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' => 'omitted',
  'secret' => 'omitted',
  'trusted_domains' => 
  array (
    1 => 'localhost',
    2 => '127.0.0.1',
    3 => '64.20.57.51',
    4 => 'cloud.the-gdn.net',
  ),
  'datadirectory' => '/var/snap/nextcloud/common/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '24.0.3.2',
  'overwrite.cli.url' => 'http://localhost',
  'dbname' => 'nextcloud',
  'dbhost' => 'omitted',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'omitted',
  'dbpassword' => 'omitted',
  'installed' => true,
  'instanceid' => 'omitted',
  'trusted_proxies' => 
  array (
    1 => '127.0.0.1',
    2 => '[::1]',
  ),
  'maintenance' => false,
);

The output of your Apache/nginx/system log in /var/log/____:

No errors or warnings

Output errors in nextcloud.log in /var/www/ or as admin user in top right menu, filtering for errors. Use a pastebin service if necessary.

{"reqId":"Caefij5XzylSuzhP4Dx1","level":2,"time":"2022-08-13T21:57:14+00:00","remoteAddr":"127.0.0.1","user":"--","app":"core","method":"GET","url":"/","message":"Trusted domain error. \"127.0.0.1\" tried to access using \"cloud.the-gdn.net\" as host.","userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0","version":"24.0.3.2","data":{"app":"core"}}