docker icon indicating copy to clipboard operation
docker copied to clipboard

nextcloud update 21 error message with /.well-known/webfinger & /.well-known/nodeinfo

Open RedJohn14 opened this issue 5 years ago • 30 comments

After I have upgraded my nextcloud to nextcloud version 21 I have this error messages:

I see this error messages in the chrome developer console tab console

overview:1 Refused to connect to 'http://mynextcloud.de/index.php/.well-known/webfinger' because it violates the following Content Security Policy directive: "connect-src 'self'".

overview:1 Refused to connect to 'http://mynextcloud.de/index.php/.well-known/nodeinfo' because it violates the following Content Security Policy directive: "connect-src 'self'".

I have the following config in use:

one docker container with nextcloud:fpm-alpine one docker container with nginx:alpine and the nginx config from here https://docs.nextcloud.com/server/latest/admin_manual/installation/nginx.html

one docker container with traefik

the nginx container have some traefik 2 lables like this here:

    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.nextcloud-app.entrypoints=http"
      - "traefik.http.routers.nextcloud-app.rule=Host(`mynextcloud.de`)"
      - "traefik.http.middlewares.nextcloud-app-https-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.nextcloud-app.middlewares=nextcloud-app-https-redirect"
      - "traefik.http.routers.nextcloud-app-secure.entrypoints=https"
      - "traefik.http.routers.nextcloud-app-secure.rule=Host(`mynextcloud.de`)"
      - "traefik.http.routers.nextcloud-app-secure.tls=true"
      - "traefik.http.routers.nextcloud-app-secure.tls.certresolver=http"
      - "traefik.http.routers.nextcloud-app-secure.service=nextcloud-app"
      - "traefik.http.services.nextcloud-app.loadbalancer.server.port=80"
      - "traefik.docker.network=proxy"
      - "traefik.http.routers.nextcloud-app-secure.middlewares=nextcloud-dav,secHeaders@file"
      - "traefik.http.middlewares.nextcloud-dav.replacepathregex.regex=^/.well-known/ca(l|rd)dav"
      - "traefik.http.middlewares.nextcloud-dav.replacepathregex.replacement=/remote.php/dav/"

(https://goneuland.de/nextcloud-server-mit-docker-compose-und-traefik-installieren/)

Nextcloud can open without errors, BUT in the overview I have this error messages:

Dein Web-Server ist nicht richtig eingerichtet um "/.well-known/webfinger" aufzulösen. Weitere Informationen findest Du in der Dokumentation.
Dein Web-Server ist nicht richtig eingerichtet um "/.well-known/nodeinfo" aufzulösen. Weitere Informationen findest Du in der Dokumentation.

Any ideas how to fix? I search now for some days ... :-( This error messages is after nextcloud 21 update

RedJohn14 avatar Mar 11 '21 22:03 RedJohn14

I manage to correct the error, but maybe there is something better to do. Traefik need to manage the redirection, here the interesting label:

      - "traefik.http.routers.nextcloud.middlewares=nextcloud-dav, nextcloud-wellknown"
      - "traefik.http.middlewares.nextcloud-dav.replacepathregex.regex=^/.well-known/(card|cal)dav"
      - "traefik.http.middlewares.nextcloud-dav.replacepathregex.replacement=/remote.php/dav/"
      - "traefik.http.middlewares.nextcloud-wellknown.replacepathregex.regex=^(/.well-known.*)"
      - "traefik.http.middlewares.nextcloud-wellknown.replacepathregex.replacement=/index.php$${1}"

gibald avatar Mar 15 '21 14:03 gibald

Es gelingt mir, den Fehler zu korrigieren, aber vielleicht gibt es etwas Besseres zu tun. Traefik muss die Umleitung verwalten, hier das interessante Label:

      - "traefik.http.routers.nextcloud.middlewares=nextcloud-dav, nextcloud-webfinger"
      - "traefik.http.middlewares.nextcloud-dav.redirectregex.regex=/.well-known/(card|cal)dav"
      - "traefik.http.middlewares.nextcloud-dav.redirectregex.replacement=/remote.php/dav/"
      - "traefik.http.middlewares.nextcloud-webfinger.redirectregex.regex=^https://mynextcloud.com(/.well-known.*)"
      - "traefik.http.middlewares.nextcloud-webfinger.redirectregex.replacement=https://mynextcloud.com/index.php$${1}"

@gibald Thanks for your answer ;-) I have tested the lables like this:

      traefik.http.routers.nc-nxtc.middlewares: nc-nxtc, nc-dav, nc-webfinger, nc-sslheaders
      # # Middleware cloud adds additional headers:
      traefik.http.middlewares.nc-nxtc.headers.customFrameOptionsValue: SAMEORIGIN
      traefik.http.middlewares.nc-nxtc.headers.framedeny: true
      traefik.http.middlewares.nc-nxtc.headers.sslredirect: true
      traefik.http.middlewares.nc-nxtc.headers.stsIncludeSubdomains: true
      traefik.http.middlewares.nc-nxtc.headers.stsPreload: true
      traefik.http.middlewares.nc-nxtc.headers.stsSeconds: 15552000
      traefik.http.middlewares.nc-sslheaders.headers.customRequestHeaders.X-Forwarded-Proto: https

      traefik.http.middlewares.nc-dav.replacepathregex.regex: ^/.well-known/ca(l|rd)dav
      traefik.http.middlewares.nc-dav.replacepathregex.replacement: /remote.php/dav/
      traefik.http.middlewares.nc-webfinger.redirectregex.regex: ^https://mynextcloud.com(/.well-known.*)
      traefik.http.middlewares.nc-webfinger.redirectregex.replacement: https://mynextcloud.com/index.php$${1}

BUT I have still the "error" messages in nextcloud webinterface. :-(

Any idea? Can you share me your config? I have used new nginx config from here:

https://docs.nextcloud.com/server/latest/admin_manual/installation/nginx.html

Traefik make the ssl connections and connected to nextcloud via http in the backend (container).

RedJohn14 avatar Mar 15 '21 15:03 RedJohn14

@gibald thx this works for me, but any chance the https://mynextcloud.com/ part can be generic as well?

I tried this, without success ...

- traefik.http.middlewares.nextcloud-dav.redirectregex.regex=/.well-known/ca(rd|l)dav
- traefik.http.middlewares.nextcloud-dav.redirectregex.replacement=/remote.php/dav/
- traefik.http.middlewares.nextcloud-wellknown.redirectregex.regex=/.well-known/(.*)
- traefik.http.middlewares.nextcloud-wellknown.redirectregex.replacement=/index.php$${1}

and

- traefik.http.middlewares.nextcloud-wellknown.redirectregex.regex=/.well-known/(webfinger|nodeinfo)
- traefik.http.middlewares.nextcloud-wellknown.redirectregex.replacement=/index.php$${1}

jokay avatar Mar 15 '21 15:03 jokay

@gibald thx this works for me, but any chance the https://mynextcloud.com/ part can be generic as well?

@jokay Did you use nginx with fpm? Can you share me your traefik config, nginx config? Any special settings in nextcloud? My config have the error also with this changes ... :-(

RedJohn14 avatar Mar 15 '21 15:03 RedJohn14

I have the new nginx config too. I pretty sure you have to remove the "^" before "/.well-known/ca(l|rd)dav". It give you a error with "/.well-known/caldav", no ? Try with the double "$", like : traefik.http.middlewares.nc-webfinger.redirectregex.replacement: https://mynextcloud.com/index.php${1}

I need it because I'm using another style, you are using yaml.

@gibald thx this works for me, but any chance the https://mynextcloud.com/ part can be generic as well?

Maybe with a better regex. I add the host because i add a loop like /index.php/index.php/index.php/index.php/.well-known/webfinger

gibald avatar Mar 15 '21 15:03 gibald

@jokay Did you use nginx with fpm? Can you share me your traefik config, nginx config? Any special settings in nextcloud? My config have the error also with this changes ... :-(

yes, with nginx config from official documentation, adapted to serve on http only (same setup as you).

I suspect the ^ as well, like @gibald already wrote.

jokay avatar Mar 15 '21 15:03 jokay

@RedJohn14 this is the config I use:

This is the nginx confd

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

server {
    listen 80;
    listen [::]:80;
    server_name {your-domain-for-nextcloud};

    # HSTS settings
    # WARNING: Only add the preload option once you read about
    # the consequences in https://hstspreload.org/. This option
    # will add the domain to a hardcoded list that is shipped
    # in all major browsers and getting removed from this list
    # could take several months.
    #add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;

    # 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;

    # Pagespeed is not supported by Nextcloud, so if your server is built
    # with the `ngx_pagespeed` module, uncomment this line to disable it.
    #pagespeed off;

    # HTTP response headers borrowed from Nextcloud `.htaccess`
    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/html;

    # Specify how to handle directories -- specifying `/index.php$request_uri`
    # here as the fallback means that Nginx always exhibits the desired behaviour
    # when a client requests a path that corresponds to a directory that exists
    # on the server. In particular, if that directory contains an index.php file,
    # that file is correctly served; if it doesn't, then the request is passed to
    # the front-end controller. This consistent behaviour means that we don't need
    # to specify custom rules for certain paths (e.g. images and other assets,
    # `/updater`, `/ocm-provider`, `/ocs-provider`), and thus
    # `try_files $uri $uri/ /index.php$request_uri`
    # always provides the desired behaviour.
    index index.php index.html /index.php$request_uri;

    # Rule borrowed from `.htaccess` to handle Microsoft DAV clients
    location = / {
        if ( $http_user_agent ~ ^DavClnt ) {
            return 302 /remote.php/webdav/$is_args$args;
        }
    }

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

    # Make a regex exception for `/.well-known` so that clients can still
    # access it despite the existence of the regex rule
    # `location ~ /(\.|autotest|...)` which would otherwise handle requests
    # for `/.well-known`.
    location ^~ /.well-known {
        # The following 6 rules are borrowed from `.htaccess`

        location = /.well-known/carddav     { return 301 /remote.php/dav/; }
        location = /.well-known/caldav      { return 301 /remote.php/dav/; }
        # Anything else is dynamically handled by Nextcloud
        location ^~ /.well-known            { return 301 /index.php$uri; }

        try_files $uri $uri/ =404;
    }

    # Rules borrowed from `.htaccess` to hide certain paths from clients
    location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/)  { return 404; }
    location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console)              { return 404; }

    # Ensure this block, which passes PHP files to the PHP process, is above the blocks
    # which handle static assets (as seen below). If this block is not declared first,
    # then Nginx will encounter an infinite rewriting loop when it prepends `/index.php`
    # to the URI, resulting in a HTTP 500 error response.
    location ~ \.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;

        fastcgi_param modHeadersAvailable true;         # Avoid sending the security headers twice
        fastcgi_param front_controller_active true;     # Enable pretty urls
        fastcgi_pass php-handler;

        fastcgi_intercept_errors on;
        fastcgi_request_buffering off;
    }

    location ~ \.(?:css|js|svg|gif)$ {
        try_files $uri /index.php$request_uri;
        expires 6M;         # Cache-Control policy borrowed from `.htaccess`
        access_log off;     # Optional: Don't log access to assets
    }

    location ~ \.woff2?$ {
        try_files $uri /index.php$request_uri;
        expires 7d;         # Cache-Control policy borrowed from `.htaccess`
        access_log off;     # Optional: Don't log access to assets
    }

    location / {
        try_files $uri $uri/ /index.php$request_uri;
    }
}

and traefik labels I use

labels:
  - traefik.enable=true
  - traefik.http.routers.nextcloud.entrypoints=https
  - traefik.http.routers.nextcloud.tls=true
  - traefik.http.routers.nextcloud.rule=Host(`{your-domain-for-nextcloud}`)
  - traefik.http.services.nextcloud.loadbalancer.server.port=80
  - traefik.http.middlewares.nextcloud-dav.redirectregex.regex=/.well-known/ca(rd|l)dav
  - traefik.http.middlewares.nextcloud-dav.redirectregex.replacement=/remote.php/dav/
  - traefik.http.middlewares.nextcloud-wellknown.redirectregex.regex=^https://{your-domain-for-nextcloud}(/.well-known.*)
  - traefik.http.middlewares.nextcloud-wellknown.redirectregex.replacement=https://{your-domain-for-nextcloud}/index.php$${1}
  - traefik.http.routers.nextcloud.middlewares=nextcloud-dav@docker,nextcloud-wellknown@docker

jokay avatar Mar 15 '21 15:03 jokay

I have the new nginx config too. I pretty sure you have to remove the "^" before "/.well-known/ca(l|rd)dav". It give you a error with "/.well-known/caldav", no ? Try with the double "$", like : traefik.http.middlewares.nc-webfinger.redirectregex.replacement: https://mynextcloud.com/index.php${1}

I need it because I'm using another style, you are using yaml.

@gibald thx this works for me, but any chance the https://mynextcloud.com/ part can be generic as well?

Maybe with a better regex. I add the host because i add a loop like /index.php/index.php/index.php/index.php/.well-known/webfinger

@gibald @jokay Okay have now edit my config (yes see that you used some other .yml style.

      traefik.http.middlewares.nc-dav.replacepathregex.regex: /.well-known/ca(l|rd)dav
      traefik.http.middlewares.nc-dav.replacepathregex.replacement: /remote.php/dav/
      traefik.http.middlewares.nc-webfinger.redirectregex.regex: https://mynextcloud.com(/.well-known.*)
      traefik.http.middlewares.nc-webfinger.redirectregex.replacement: https://mynextcloud.com/index.php$${1}

BUT I have still the error :-( any ideas? Sorry ...

RedJohn14 avatar Mar 15 '21 15:03 RedJohn14

edit: Ok doubled $ for escaping is needed for you as well

gibald avatar Mar 15 '21 15:03 gibald

@RedJohn14 strange.. can you compare the configs I posted?

info

The only warning I still get is for php-imagick which is already discussed here.

jokay avatar Mar 15 '21 15:03 jokay

try:

      traefik.http.middlewares.nc-dav.replacepathregex.regex: /.well-known/ca(l|rd)dav
      traefik.http.middlewares.nc-dav.replacepathregex.replacement: /remote.php/dav/
      traefik.http.middlewares.nc-webfinger.redirectregex.regex: https://mynextcloud.com(/.well-known.*)
      traefik.http.middlewares.nc-webfinger.redirectregex.replacement: https://mynextcloud.com/index.php${1}

I only remove one $ at the end

@gibald With this setting I have this error message:

Invalid interpolation format for "labels" option in service "nginx-nc": "https://mynexcloud.com/index.php${1}"

RedJohn14 avatar Mar 15 '21 15:03 RedJohn14

@RedJohn14 strange.. can you compare the configs I posted?

info

The only warning I still get is for php-imagick which is already discussed here.

@jokay Yes I compare configs, you are using same configs, I have only "other" .yml style and have error still ... :-(

Yes the other issue I have too, but can fix it manual. Any idea to install php-imagick in nextcloud-fpm-alpine?

RedJohn14 avatar Mar 15 '21 15:03 RedJohn14

What about setting your domain instead of ~mynexcloud.com~?

@gibald @jokay

Yes I have insert my domain in my .yml config but if i try docker-compose up -d I have this error message:

error message: Invalid interpolation format for "labels" option in service "nginx-nc": "https://mynextcloud.com/index.php${1}"

lable config:

      traefik.http.middlewares.nc-dav.replacepathregex.regex: /.well-known/ca(l|rd)dav
      traefik.http.middlewares.nc-dav.replacepathregex.replacement: /remote.php/dav/
      traefik.http.middlewares.nc-webfinger.redirectregex.regex: https://mynextcloud.com(/.well-known.*)
      traefik.http.middlewares.nc-webfinger.redirectregex.replacement: https://mynextcloud.com/index.php${1}

I think my label config is some different like yours. Any idea what my mistake is?

RedJohn14 avatar Mar 15 '21 15:03 RedJohn14

Well then I'm out of ideas 😉

jokay avatar Mar 15 '21 15:03 jokay

Your error Invalid interpolation format for "labels" option in service "nginx-nc": "https://mynextcloud.com/index.php${1}" is because of my bad idea, you also need the double $ fro escaping.

You can try :

traefik.http.middlewares.nc-dav.replacepathregex.regex: ^/.well-known/ca(l|rd)dav
traefik.http.middlewares.nc-dav.replacepathregex.replacement: /remote.php/dav/
traefik.http.middlewares.nc-webfinger.replacepathregex.regex: ^(/.well-known.*)
traefik.http.middlewares.nc-webfinger.replacepathregex.replacement: /index.php$${1}

I update my solution, i didn't saw the difference between RedirectRegex and ReplacePathRegex

gibald avatar Mar 15 '21 16:03 gibald

Your error Invalid interpolation format for "labels" option in service "nginx-nc": "https://mynextcloud.com/index.php${1}" is because of my bad idea, you also need the double $ fro escaping.

You can try :

traefik.http.middlewares.nc-dav.replacepathregex.regex: ^/.well-known/ca(l|rd)dav
traefik.http.middlewares.nc-dav.replacepathregex.replacement: /remote.php/dav/
traefik.http.middlewares.nc-webfinger.replacepathregex.regex: ^(/.well-known.*)
traefik.http.middlewares.nc-webfinger.replacepathregex.replacement: /index.php$${1}

I update my solution, i didn't saw the difference between RedirectRegex and ReplacePathRegex

@gibald Okay I will try, I have updated now my traefik labels to the other style and it fix the error. I will try your solutions now!

RedJohn14 avatar Mar 15 '21 16:03 RedJohn14

Your error Invalid interpolation format for "labels" option in service "nginx-nc": "https://mynextcloud.com/index.php${1}" is because of my bad idea, you also need the double $ fro escaping.

You can try :

traefik.http.middlewares.nc-dav.replacepathregex.regex: ^/.well-known/ca(l|rd)dav
traefik.http.middlewares.nc-dav.replacepathregex.replacement: /remote.php/dav/
traefik.http.middlewares.nc-webfinger.replacepathregex.regex: ^(/.well-known.*)
traefik.http.middlewares.nc-webfinger.replacepathregex.replacement: /index.php$${1}

I update my solution, i didn't saw the difference between RedirectRegex and ReplacePathRegex

Okay this settings fix also my issue ;-) THANK you very much for your support !!!

RedJohn14 avatar Mar 15 '21 16:03 RedJohn14

I update my solution, i didn't saw the difference between RedirectRegex and ReplacePathRegex

@gibald works and is generic, thank you very much for this 🎉

jokay avatar Mar 15 '21 16:03 jokay

Hi Folks,

TY for all the suggested solutions and time invested. I managed to fix it this way:

Source: https://twatzl.eu/blog/2020-08-01_5_nextcloud/

  - "traefik.http.middlewares.nextcloud-dav.replacepathregex.regex=^/.well-known/ca(l|rd)dav"
  - "traefik.http.middlewares.nextcloud-dav.replacepathregex.replacement=/remote.php/dav/"
  - "traefik.http.middlewares.nc-header.headers.referrerPolicy=no-referrer"
  - "traefik.http.middlewares.nc-header.headers.stsSeconds=31536000"
  - "traefik.http.middlewares.nc-header.headers.forceSTSHeader=true"
  - "traefik.http.middlewares.nc-header.headers.stsPreload=true"
  - "traefik.http.middlewares.nc-header.headers.stsIncludeSubdomains=true"
  - "traefik.http.middlewares.nc-header.headers.browserXssFilter=true"
  - "traefik.http.middlewares.nc-header.headers.customFrameOptionsValue=SAMEORIGIN"
  - "traefik.http.middlewares.nc-header.headers.customRequestHeaders.X-Forwarded-Proto=https"
  - "traefik.http.routers.nextcloud-secure.middlewares=nextcloud-dav,nc-header"

BR G.

isms-core-project avatar Apr 03 '21 12:04 isms-core-project

  • "traefik.http.middlewares.nextcloud-dav.replacepathregex.regex=^/.well-known/ca(l|rd)dav"
  • "traefik.http.middlewares.nextcloud-dav.replacepathregex.replacement=/remote.php/dav/"
  • "traefik.http.middlewares.nc-header.headers.referrerPolicy=no-referrer"
  • "traefik.http.middlewares.nc-header.headers.stsSeconds=31536000"
  • "traefik.http.middlewares.nc-header.headers.forceSTSHeader=true"
  • "traefik.http.middlewares.nc-header.headers.stsPreload=true"
  • "traefik.http.middlewares.nc-header.headers.stsIncludeSubdomains=true"
  • "traefik.http.middlewares.nc-header.headers.browserXssFilter=true"
  • "traefik.http.middlewares.nc-header.headers.customFrameOptionsValue=SAMEORIGIN"
  • "traefik.http.middlewares.nc-header.headers.customRequestHeaders.X-Forwarded-Proto=https"
  • "traefik.http.routers.nextcloud-secure.middlewares=nextcloud-dav,nc-header"

After lot of search this solution worked for me. Thank you!

martinezpenya avatar Apr 15 '21 18:04 martinezpenya