404 Not Found error

Hi! I’m using Nextcloud at my home server and all works well in my LAN, wen I’m trying to open NC by local ip, like this: http://192.168.1.217:83/nextcloud/.
I don’t have public IP, so I need to use Cloudflare tunnel for access my server outside my home net.
But if I’ve try to open NC by domain name like this: nextcloud.mydomain.cf I have this error in nginx log:

[error] 129676#129676: *190 open() "/var/www/favicon.ico" failed (2: No such file or directory), client: 127.0.0.1, server: nextcloud.mydomain.cf, request: "GET /favicon.ico HTTP/1.1", host: "nextcloud.mydomain.cf"

and web browser display this error:

404 Not Found

my nextcloud.conf:

upstream php-handler {
   
    server unix:/var/run/php/php7.4-fpm.sock;
}


server {
    listen 83;

    server_name nextcloud.mydomain.cf localhost;

    
    add_header Referrer-Policy "no-referrer" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-Download-Options "noopen" always;
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Permitted-Cross-Domain-Policies "none" always;
    add_header X-Robots-Tag "none" always;
    add_header X-XSS-Protection "1; mode=block" always;

    # Remove X-Powered-By, which is an information leak
    fastcgi_hide_header X-Powered-By;

    # Path to the root of your installation
    root /var/www/;

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    
    location = /.well-known/carddav {
      return 301 $scheme://$host:$server_port/nextcloud/remote.php/dav;
    }
    location = /.well-known/caldav {
      return 301 $scheme://$host:$server_port/nextcloud/remote.php/dav;
    }

    location /.well-known/acme-challenge { }

    location ^~ /nextcloud {

        # set max upload size
        client_max_body_size 512M;
        fastcgi_buffers 64 4K;

        # Enable gzip but do not remove ETag headers
        gzip on;
        gzip_vary on;
        gzip_comp_level 4;
        gzip_min_length 256;
        gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
        gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;

        # Uncomment if your server is build with the ngx_pagespeed module
        # This module is currently not supported.
        #pagespeed off;

        location /nextcloud {
            rewrite ^ /nextcloud/index.php;
        }

        location ~ ^\/nextcloud\/(?:build|tests|config|lib|3rdparty|templates|data)\/ {
            deny all;
        }
        location ~ ^\/nextcloud\/(?:\.|autotest|occ|issue|indie|db_|console) {
            deny all;
        }

        location ~ ^\/nextcloud\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy)\.php(?:$|\/) {
            fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
            set $path_info $fastcgi_path_info;
            try_files $fastcgi_script_name =404;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $path_info;
            #fastcgi_param HTTPS on;
            # Avoid sending the security headers twice
            fastcgi_param modHeadersAvailable true;
            # Enable pretty urls
            fastcgi_param front_controller_active true;
            fastcgi_pass php-handler;
            fastcgi_intercept_errors on;
            fastcgi_request_buffering off;
        }

        location ~ ^\/nextcloud\/(?:updater|oc[ms]-provider)(?:$|\/) {
            try_files $uri/ =404;
            index index.php;
        }

        # Adding the cache control header for js, css and map files
        # Make sure it is BELOW the PHP block
        location ~ ^\/nextcloud\/.+[^\/]\.(?:css|js|woff2?|svg|gif|map)$ {
            try_files $uri /nextcloud/index.php$request_uri;
            add_header Cache-Control "public, max-age=15778463";
            
            add_header Referrer-Policy "no-referrer" always;
            add_header X-Content-Type-Options "nosniff" always;
            add_header X-Download-Options "noopen" always;
            add_header X-Frame-Options "SAMEORIGIN" always;
            add_header X-Permitted-Cross-Domain-Policies "none" always;
            add_header X-Robots-Tag "none" always;
            add_header X-XSS-Protection "1; mode=block" always;

            # Optional: Don't log access to assets
            access_log off;
        }

        location ~ ^\/nextcloud\/.+[^\/]\.(?:png|html|ttf|ico|jpg|jpeg|bcmap|mp4|webm)$ {
            try_files $uri /nextcloud/index.php$request_uri;
            # Optional: Don't log access to other assets
            access_log off;
        }
    }
}

my config.php

<?php
$CONFIG = array (
  'instanceid' => 'XXXXXXXXXXXX',
  'passwordsalt' => XXXXXXXXXXXXXXX',
  'secret' => 'XXXXXXXXXXXXXXX',
  'trusted_domains' => 
  array (
    0 => '192.168.1.217',
    1 => 'mydomain.cf',
    2 => 'localhost',
  ),
  'datadirectory' => '/var/www/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '22.2.5.1',
  'overwrite.cli.url' => 'htts://nextcloud.minhex.cf',
  'dbname' => 'test',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'test',
  'dbpassword' => 'test',
  'installed' => true,
);

any ideas appreciated

You try to get access to your Nextcloud server by calling

but your instance is named

in config.php.

And below you have the line

in config.php, too.
“htts” is wrong and you use three different names.

Mornsgrans, omg you right, thx! I fix it, but unfortunately my problem still exists:

2022/04/20 10:22:56 [error] 147447#147447: *252 directory index of "/var/www/" is forbidden, client: 127.0.0.1, server: nextcloud.mydomain.cf, request: "GET / HTTP/1.1", host: "nextcloud.mydomain.cf"
2022/04/20 10:22:56 [error] 147447#147447: *252 open() "/var/www/favicon.ico" failed (2: No such file or directory), client: 127.0.0.1, server: nextcloud.mydomain.cf, request: "GET /favicon.ico HTTP/1.1", host: "nextcloud.mydomain.cf"
2022/04/20 10:23:06 [error] 147447#147447: *252 directory index of "/var/www/" is forbidden, client: 127.0.0.1, server: nextcloud.minhex.cf, request: "GET / HTTP/1.1", host: "nextcloud.mydomain.cf"

And if you don’t use the default ports, you need to specify it in the hostnames:
1 => 'nextcloud.mydomain.cf:83',

'overwrite.cli.url' => 'https://nextcloud.minhex.cf:83/nextcloud',

Why do you put nextcloud in a subfolder when there is nothing in the main root of the domain? It is better to use a specific subdomain for nextcloud.

How does it work with cloudflare, is this a proxy service? In this case hostnames, ports etc. are not properly recognized and you might want to adapt the overwrite* variables that you can set in the config.php: server/config.sample.php at master · nextcloud/server · GitHub

I’m using subfolders because I have some stuff on my webserver besides nextcloud. )

Right, cloudflare tunnel works like a reverse proxy, so I need port 83 only for internal use, and as I wrote above all works well in my LAN. CF redirect this port to 80 or 443

I’ve tride to put this variables to my config.php

'overwritehost' => 'nextcloud.mydomain.cf',
 'overwriteprotocol' => 'https',

but nothing changes, still have error like this in my nginx error.log:

directory index of "/var/www/" is forbidden, client: 127.0.0.1, server: nextcloud.mydomain.cf, request: "GET / HTTP/1.1", host: "nextcloud.mydomain.cf"

Yes, I made it! With this config NC work like a charm behind CF tunnel:

upstream php-handler {
    
    server unix:/var/run/php/php7.4-fpm.sock;
}

server {
    
    listen 83;
    server_name nextcloud.mydomain.cf localhost;
    add_header X-Content-Type-Options nosniff;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;
    add_header X-Download-Options noopen;
    add_header X-Permitted-Cross-Domain-Policies none;

    
    root /var/www/nextcloud/;
    
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    

    location = /.well-known/carddav {
      return 301 $scheme://$host/remote.php/dav;
    }
    location = /.well-known/caldav {
      return 301 $scheme://$host/remote.php/dav;
    }

    # set max upload size
    client_max_body_size 512M;
    fastcgi_buffers 64 4K;

    # Disable gzip to avoid the removal of the ETag header
    gzip off;

    
    error_page 403 /core/templates/403.php;
    error_page 404 /core/templates/404.php;

    location / {
        rewrite ^ /index.php$uri;
    }

    location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
        deny all;
    }
    location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
        deny all;
    }

    location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        #fastcgi_param HTTPS on;
        #Avoid sending the security headers twice
        fastcgi_param modHeadersAvailable true;
        fastcgi_param front_controller_active true;
        fastcgi_pass php-handler;
        fastcgi_intercept_errors on;
        fastcgi_request_buffering off;
    }

    location ~ ^/(?:updater|ocs-provider)(?:$|/) {
        try_files $uri/ =404;
        index index.php;
    }

    # Adding the cache control header for js and css files
    # Make sure it is BELOW the PHP block
    location ~* \.(?:css|js)$ {
        try_files $uri /index.php$uri$is_args$args;
        add_header Cache-Control "public, max-age=7200";
        # Add headers to serve security related headers (It is intended to
        # have those duplicated to the ones above)
        # Before enabling Strict-Transport-Security headers please read into
        # this topic first.
        # add_header Strict-Transport-Security "max-age=15768000;
        #  includeSubDomains; preload;";
        add_header X-Content-Type-Options nosniff;
        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Robots-Tag none;
        add_header X-Download-Options noopen;
        add_header X-Permitted-Cross-Domain-Policies none;
        # Optional: Don't log access to assets
        access_log off;
    }

    location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
        try_files $uri /index.php$uri$is_args$args;
        # Optional: Don't log access to other assets
        access_log off;
    }
}

1 Like