Caddy + Nextcloud (fpm) + Collabora - individual containers and docker-compose

You need to also mount /var/www/html from nextcloud into the Caddy container

This should point to the nextcloud container, not 127.0.0.1.

I do not find an example in that article from Wiki on how to do this.

I presumed, from the docker-compose.yml part of Nginx, that was sufficient to use “volumes_from”. There is no mount of /var/www/html in that part of the file. By analogy I made the same for Caddy.

Yeah, that might do.

But still, 127.0.0.1 will not work because that tells Caddy to try to connect to something inside the Caddy container itself, but there’s nothing there.

Use nextcloud-app:9000 instead

After change 127.0.0.1:9000 to nextcloud-app:9000 the error message seems the same, only changing 127.0.0.1 by 172.20.0.4 (the IP autoassigned by Docker).

{"level":"debug","ts":1652024826.3810058,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"nextcloud-app:9000","duration":0.000762927,"request":{"remote_ip":"10.22.22.33","remote_port":"60882","proto":"HTTP/2.0","method":"GET","host":"nextcloud.local.cites.aop","uri":"index.php","headers":{"Sec-Fetch-Site":["same-origin"],"Te":["trailers"],"Sec-Fetch-Dest":["image"],"Accept-Encoding":["gzip, deflate, br"],"X-Forwarded-For":["10.22.22.33"],"Sec-Fetch-Mode":["no-cors"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0"],"Accept-Language":["pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3"],"Accept":["image/avif,image/webp,*/*"],"X-Forwarded-Proto":["https"],"X-Forwarded-Host":["nextcloud.local.cites.aop"],"Referer":["https://nextcloud.local.cites.aop/"]},"tls":{"resumed":false,"version":772,"cipher_suite":4867,"proto":"h2","server_name":"nextcloud.local.cites.aop"}},"error":"dialing backend: dial tcp 172.20.0.4:9000: connect: connection refused"}
{"level":"error","ts":1652024826.3810594,"logger":"http.log.error","msg":"dialing backend: dial tcp 172.20.0.4:9000: connect: connection refused","request":{"remote_ip":"10.22.22.33","remote_port":"60882","proto":"HTTP/2.0","method":"GET","host":"nextcloud.local.cites.aop","uri":"/favicon.ico","headers":{"Sec-Fetch-Dest":["image"],"Accept":["image/avif,image/webp,*/*"],"Accept-Encoding":["gzip, deflate, br"],"Referer":["https://nextcloud.local.cites.aop/"],"Sec-Fetch-Mode":["no-cors"],"Sec-Fetch-Site":["same-origin"],"Te":["trailers"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0"],"Accept-Language":["pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3"]},"tls":{"resumed":false,"version":772,"cipher_suite":4867,"proto":"h2","server_name":"nextcloud.local.cites.aop"}},"duration":0.000966479,"status":502,"err_id":"yd1wkd6t0","err_trace":"reverseproxy.statusError (reverseproxy.go:1196)"}

Some info from ctop:

 ctop - 12:53:49 -03   5 containers

     NAME                           CID          CPU                MEM                NET RX/TX          IO R/W             PIDS UPTIME

   ⏵ nextcloud-app                  31eb0de23767          0%             472M / 4G     9M / 15M           0B / 0B            3    6m50s
   ⏵ nextcloud-cache                aba0c5337117          0%              2M / 2G      3K / 319B          0B / 0B            5    6m51s
   ⏵ nextcloud-collabora            c817318ef0b7          0%             775M / 4G     2K / 0B            0B / 0B            10   6m49s
   ⏵ nextcloud-db                   b8e4325296bc          0%              80M / 4G     15M / 9M           0B / 0B            7    6m51s
   ⏵ nextcloud-web                  c7342f51e57b          0%              11M / 4G     7K / 6K            0B / 0B            9    6m50s
┌───────────────────────────────────────────────────────────────┐
│  id      | 31eb0de23767                                       │
│  name    | nextcloud-app                                      │
│  image   | nextcloud:24.0.0-fpm-alpine                        │
│  ports   | 0.0.0.0:9000 -> 9000/tcp                           │
│          | :::9000 -> 9000/tcp                                │
│  IPs     | nextcloud_default:172.20.0.4                       │
│  state   | running                                            │
│  created | Sun May 8 15:46:51 2022                            │
│  uptime  | 6m50s                                              │
│  health  |                                                    │
└───────────────────────────────────────────────────────────────┘
┌───────────────────────────────────────────────────────────────┐
│  id      | c7342f51e57b                                       │
│  name    | nextcloud-web                                      │
│  image   | caddy:2.5.1-alpine                                 │
│  ports   | 2019/tcp                                           │
│          | 0.0.0.0:443 -> 443/tcp                             │
│          | :::443 -> 443/tcp                                  │
│          | 0.0.0.0:80 -> 80/tcp                               │
│          | :::80 -> 80/tcp                                    │
│  IPs     | nextcloud_default:172.20.0.5                       │
│  state   | running                                            │
│  created | Sun May 8 15:46:51 2022                            │
│  uptime  | 6m50s                                              │
│  health  |                                                    │
└───────────────────────────────────────────────────────────────┘

Strange. Are you sure php-fpm is actually listening on port 9000? It might be configured to do something else :thinking: what’s in the app container’s logs?

Yesterday I had a very, very bad trip with the distro I usually use, that is Arch. If you want to know I can tell you.

I just installed a new Ubuntu Server 22.04 in my Proxmox, copy docker-compose.yml and Caddyfile from previous interaction and will try it now.

Initial logs from nextcloud-web container (Caddy) and nextcloud-app (nextcloud:24.0.0-fpm-alpine):

[+] Running 10/10
 ⠿ Network nextcloud_default                  Created                                                                                              0.1s
 ⠿ Volume "nextcloud_nextcloud-app"           Created                                                                                              0.0s
 ⠿ Volume "nextcloud_nextcloud-caddy-data"    Created                                                                                              0.0s
 ⠿ Volume "nextcloud_nextcloud-caddy-config"  Created                                                                                              0.0s
 ⠿ Volume "nextcloud_nextcloud-db"            Created                                                                                              0.0s
 ⠿ Container nextcloud-db                     Started                                                                                              1.1s
 ⠿ Container nextcloud-cache                  Started                                                                                              1.1s
 ⠿ Container nextcloud-app                    Started                                                                                              1.1s
 ⠿ Container nextcloud-web                    Started                                                                                              1.5s
 ⠿ Container nextcloud-collabora              Started                                                                                              1.9s
{"level":"info","ts":1652027854.8559625,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
{"level":"warn","ts":1652027854.8588479,"msg":"Caddyfile input is not formatted; run the 'caddy fmt' command to fix inconsistencies","adapter":"caddyfile","file":"/etc/caddy/Caddyfile","line":6}
{"level":"info","ts":1652027854.8607287,"logger":"admin","msg":"admin endpoint started","address":"tcp/localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//127.0.0.1:2019"]}
{"level":"info","ts":1652027854.862389,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc0002bcd20"}
{"level":"info","ts":1652027854.8627794,"logger":"http","msg":"server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS","server_name":"srv0","https_port":443}
{"level":"info","ts":1652027854.8628585,"logger":"http","msg":"enabling automatic HTTP->HTTPS redirects","server_name":"srv0"}
{"level":"info","ts":1652027854.969344,"logger":"tls","msg":"cleaning storage unit","description":"FileStorage:/data/caddy"}
{"level":"info","ts":1652027854.969385,"logger":"tls","msg":"finished cleaning storage units"}
{"level":"debug","ts":1652027854.9694366,"logger":"http","msg":"starting server loop","address":"[::]:443","http3":false,"tls":true}
{"level":"debug","ts":1652027854.9694731,"logger":"http","msg":"starting server loop","address":"[::]:80","http3":false,"tls":false}
{"level":"info","ts":1652027854.9694836,"logger":"http","msg":"enabling automatic TLS certificate management","domains":["nextcloud.local.cites.aop"]}
{"level":"info","ts":1652027854.9700236,"logger":"tls.obtain","msg":"acquiring lock","identifier":"nextcloud.local.cites.aop"}
{"level":"info","ts":1652027854.975505,"logger":"tls.obtain","msg":"lock acquired","identifier":"nextcloud.local.cites.aop"}
{"level":"debug","ts":1652027854.9760013,"logger":"tls.obtain","msg":"trying issuer 1/1","issuer":"local"}
{"level":"debug","ts":1652027854.9763114,"logger":"pki.ca.local","msg":"using intermediate signer","serial":"80750900309849878634907328897871464525","not_before":"2022-05-08 16:37:34 +0000 UTC","not_after":"2022-05-15 16:37:34 +0000 UTC"}
{"level":"info","ts":1652027854.9768746,"logger":"tls.obtain","msg":"certificate obtained successfully","identifier":"nextcloud.local.cites.aop"}
{"level":"info","ts":1652027854.9768827,"logger":"tls.obtain","msg":"releasing lock","identifier":"nextcloud.local.cites.aop"}
{"level":"warn","ts":1652027854.9772692,"logger":"tls","msg":"stapling OCSP","error":"no OCSP stapling for [nextcloud.local.cites.aop]: no OCSP server specified in certificate","identifiers":["nextcloud.local.cites.aop"]}
{"level":"debug","ts":1652027854.9772918,"logger":"tls.cache","msg":"added certificate to cache","subjects":["nextcloud.local.cites.aop"],"expiration":1652071054,"managed":true,"issuer_key":"local","hash":"1c9f1cc62eab0af440a7b814e00182acd4018fcf8cd9a77e8c7ea316df580374","cache_size":1,"cache_capacity":10000}
{"level":"warn","ts":1652027855.0150423,"logger":"pki.ca.local","msg":"installing root certificate (you might be prompted for password)","path":"storage:pki/authorities/local/root.crt"}
{"level":"info","ts":1652027855.0152857,"msg":"Warning: \"certutil\" is not available, install \"certutil\" with \"apt install libnss3-tools\" or \"yum install nss-tools\" and try again"}
{"level":"info","ts":1652027855.0152943,"msg":"define JAVA_HOME environment variable to use the Java trust"}
{"level":"info","ts":1652027855.0543723,"msg":"certificate installed properly in linux trusts"}
{"level":"info","ts":1652027855.0545018,"msg":"autosaved config (load with --resume flag)","file":"/config/caddy/autosave.json"}
{"level":"info","ts":1652027855.0545113,"msg":"serving initial configuration"}
Configuring Redis as session handler
Initializing nextcloud 24.0.0.12 ...
New nextcloud instance
Installing with PostgreSQL database
Starting nextcloud installation
Nextcloud was successfully installed
Setting trusted domains…
System config value trusted_domains => 1 set to string nextcloud.local.cites.aop
Initializing finished
[08-May-2022 16:38:00] NOTICE: fpm is running, pid 1
[08-May-2022 16:38:00] NOTICE: ready to handle connections

I will update this post in a few minutes…

Holy shit! It happened again!!! :crazy_face:

Now Nextcloud login screen appeared (with exact the same files).

This is really frustrating…

Because of the pandemic and the home office I provided a second, faster internet link.

A few weeks ago, after a lot of searching for a problem in my configuration and not finding it, I found that it was something in the new “faster” provider. When switching to the old, “slower” link, everything worked normally.

I forgot about it and yesterday it happened again: during tests with Nextcloud, I couldn’t install apps on it. Then I remembered the problem with the new link and switched to the old one. It worked right away!

Yesterday, after a lot of talking with another developer, I found that part of the problem was only in Arch Linux, using Ubuntu 22.04 the problem didn’t occur.

Some configurations are a little more complex, involve a lot of different programs, different versions and we still have this kind of crazy stuff between different distributions.

I think I’m getting too old for this… When we used to program on coding sheets and then send them to punch cards it was easier! I was happy with COBOL and didn’t know it!

:rofl:

1 Like

So it’s working now?

I’m kinda lost, but that’s great if it works now!

Almost there…

Some things need adjustments, I think that in Caddyfile:

And I don’t know exactly how to config this part:

For the first one, you’ll need to configure nextcloud’s trusted proxies to trust the Caddy container’s IP. See the nextcloud docs for that, the proxies section.

For webdav/caldav, you can add this to your config:

redir /.well-known/carddav /remote.php/carddav 301
redir /.well-known/caldav /remote.php/caldav 301

For collabora, I think you need to put the name of the container and port so nextcloud can talk to it.

@francislavoie looks like I’ve finally managed to get EVERYTHING working locally.

Through Nginx only using HTTP for everything, with ports 80 and 9980 exposed on the host.

With our beloved Caddy, through HTTPS with a local certificate and only ports 80 and 443 exposed on the host (later I’ll do it on the VPS, with a valid certificate).

I intend to make a good documentation to add to the Wiki, for now I leave here only the necessary files/commands to reproduce locally what I did here. Just change domain/host/users/passwords to your liking.

Another important warning: always try to test on more than one distribution. I like using Arch, I learn a lot and I like its “lean” way. But there have been two or three situations where things didn’t work as they should on Arch and with the same files/settings it worked on another distribution (in this case, Ubuntu 22.04 but it could have been any other).

I begin with ~/docker/nextcloud$ docker-compose down -v to be assured that I will start from scratch. Then,

~/docker/nextcloud$ clear ; docker-compose up -d ; docker logs -f nextcloud-app

Wait till

Initializing finished
[08-May-2022 20:40:16] NOTICE: fpm is running, pid 1
[08-May-2022 20:40:16] NOTICE: ready to handle connections

Then CTRL-C and

~/docker/nextcloud$ sudo vi /var/lib/docker/volumes/nextcloud_nextcloud-app/_data/config/config.php

Add these lines

  'trusted_proxies' =>
  array (
    0 => 'nextcloud-web',
  ),
  'default_phone_region' => 'XX',

where 'XX' is your country code, this will fix the warning “Your installation has no default phone region set.” and also will add Caddy’s container (nextcloud-web) to the list of trusted proxies (fixing another warning/errors). I like to add just bellow 'trusted_domains', at line 44, because reasons.

Save the file and restart the stack.

~/docker/nextcloud$ clear ; docker-compose restart ; docker logs -f nextcloud-web

I recommend open two more tabs/windows to keep an eye on logs of nextcloud-app and nextcloud-collabora.

~/docker/nextcloud$ clear ; docker logs -f nextcloud-app

~/docker/nextcloud$ clear ; docker logs -f nextcloud-collabora

In your browser open your URL. I always save the bookmark as http://nextcloud.local.cites.aop just to see Caddy change everything to HTTPS for me! :smiley:

As at this moment I am testing locally, I must agree and accept the self-signed certificate.

Nextcloud login screen opens.

After login:

  • close welcome animation

  • click con the little bell and see that all icons are fine (one of the errors is do not see the icons)

  • dismiss all notifications and accept (or not) notifications in your browser

  • click on the “A” (top left corner) and go to “Apps”

  • choose “Office & text” on the left

  • “Download and enable” Collabora Online (third top to bottom)

  • click on the “A” (top left corner) and go to “Settings”

  • click on “Overview” (left column) and enjoy that the only “warning” is about module php-imagick; there is a controversy if it must be installed and enabled or not (something about security, I did not investigate); if you want to install and enable, the command (for this image version I choose) is docker exec nextcloud-app apk add php7-pecl-imagick

  • scroll down the left column and click on “Nextcloud Office”

  • click “Use your own server”, check “Disable certificate verification (insecure)” and enter the same URL you are using to access your Nextcloud; in my case it would be “https://nextcloud.local.cites.aop” and click “Save”

  • you must be greeted by a “Saved” on the top right corner and a green checkmarked circle “Collabora Online server is reachable”

That’s it! (easy to say now, were more than three weeks Googling, reading forums, asking for help, etc)

You have latest Nextcloud, latest Collabora, latest Postgres (may change to Mariadb, if you choose to) all “powered” by Caddy!

@francislavoie thank you, all times I asked for help you readily helped.

The next challenge is to put this “stack” (including nextcloud-web-caddy) behind the REAL reverse-proxy! Another Caddy! :wink:

Bellow,

  • docker-compose.yml

  • Caddyfile

  • nginx.conf

version: '2'
services:

  nextcloud-db:
    image: postgres:14.2-alpine
    container_name: nextcloud-db
    restart: unless-stopped
    volumes:
      - nextcloud-db:/var/lib/postgresql/data
      - /etc/localtime:/etc/localtime:ro
    environment:
      POSTGRES_USER: nextcloud
      POSTGRES_PASSWORD: password

  nextcloud-cache:
    image: redis:7.0.0-alpine
    container_name: nextcloud-cache
    restart: unless-stopped
    mem_limit: 2048m
    mem_reservation: 512m
    command: redis-server --requirepass password

  nextcloud-app:
    image: nextcloud:24.0.0-fpm-alpine
    container_name: nextcloud-app
    restart: unless-stopped
    #ports:
    #  - 9000:9000
    volumes:
      - nextcloud-app:/var/www/html
    depends_on:
      - nextcloud-db
      - nextcloud-cache
    environment:
      POSTGRES_DB: nextcloud
      POSTGRES_USER: nextcloud
      POSTGRES_PASSWORD: password
      POSTGRES_HOST: nextcloud-db
      NEXTCLOUD_ADMIN_USER: admin
      NEXTCLOUD_ADMIN_PASSWORD: password
      NEXTCLOUD_TRUSTED_DOMAINS: nextcloud.local.cites.aop
      REDIS_HOST: nextcloud-cache
      REDIS_HOST_PASSWORD: password
      SMTP_HOST: mail.local.cites.aop
      SMTP_SECURE: tls
      SMTP_PORT: 587
      SMTP_AUTHTYPE: LOGIN
      SMTP_NAME: mailer@local.cites.aop
      SMTP_PASSWORD: password
      MAIL_FROM_ADDRESS: no-reply
      MAIL_DOMAIN: local.cites.aop

  # to use Nginx instead Caddy, uncomment this "nextcloud-web",
  # comment the next and use the supplied nginx.conf
  # 
  #nextcloud-web:
  #  image: nginx:1.21.6-alpine
  #  container_name: nextcloud-web
  #  restart: unless-stopped
  #  ports:
  #    - 80:80
  #  volumes:
  #    - ./nginx.conf:/etc/nginx/nginx.conf:ro
  #  volumes_from:
  #    - nextcloud-app

  nextcloud-web:
    image: caddy:2.5.1-alpine
    container_name: nextcloud-web
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - nextcloud-caddy-data:/data
      - nextcloud-caddy-config:/config
    volumes_from:
      - nextcloud-app

  nextcloud-collabora:
    image: collabora/code:21.11.4.2.1
    container_name: nextcloud-collabora
    restart: unless-stopped
    #ports:
    #  - 9980:9980
    volumes:
      - /etc/localtime:/etc/localtime:ro
    depends_on:
      - nextcloud-web
    environment:
      - username=admin
      - password=password
      - dictionaries=en_US es_ES pt_BR
     # out of desperation, I was going to start using permutations...
     #- extra_params=--o:ssl.enable=true
     #- extra_params=--o:ssl.enable=false
     #- extra_params=--o:ssl.enable=true  --o:ssl.termination=false
     #- extra_params=--o:ssl.enable=true  --o:ssl.termination=true
     #- extra_params=--o:ssl.enable=false --o:ssl.termination=true
     #- extra_params=--o:ssl.enable=false --o:ssl.termination=false

volumes:
  nextcloud-app:
  nextcloud-db:
  nextcloud-caddy-data:
  nextcloud-caddy-config:
{
	#debug
}

nextcloud.local.cites.aop {

	acme_server
	tls internal

	encode gzip

	redir /.well-known/carddav /remote.php/dav 301
	redir /.well-known/caldav /remote.php/dav 301

	header {
		Strict-Transport-Security max-age=31536000;
	}

	@collabora {
		path /browser/*
		path /hosting/discovery
		path /hosting/capabilities
		path /cool/*
	}

	reverse_proxy @collabora https://nextcloud-collabora:9980 {
		header_up Host "nextcloud.local.cites.aop"
		transport http {
			tls_insecure_skip_verify
		}
	}

	# .htaccess / data / config / ... shouldn't be accessible from outside
	@forbidden {
		path /.htaccess
		path /data/*
		path /config/*
		path /db_structure
		path /.xml
		path /README
		path /3rdparty/*
		path /lib/*
		path /templates/*
		path /occ
		path /console.php
	}
	respond @forbidden 404

	root * /var/www/html

	php_fastcgi nextcloud-app:9000

	file_server
}
worker_processes auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    # Prevent nginx HTTP Server Detection
    server_tokens   off;

    keepalive_timeout  65;

    #gzip  on;

    upstream php-handler {
        server nextcloud-app:9000;
    }

    server {
        listen 80;

        # 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 rules in this block are an adaptation of the rules
            # in `.htaccess` that concern `/.well-known`.

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

            location /.well-known/acme-challenge    { try_files $uri $uri/ =404; }
            location /.well-known/pki-validation    { try_files $uri $uri/ =404; }

            # Let Nextcloud's API for `/.well-known` URIs handle all other
            # requests by passing them to the front-end controller.
            return 301 /index.php$request_uri;
        }

        # 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(?:$|/) {
            # Required for legacy support
            rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;

            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
        }

        # Rule borrowed from `.htaccess`
        location /remote {
            return 301 /remote.php$request_uri;
        }

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

Great! Glad you got it figured out now.

FYI, this line is redundant, the Host header is passed through as-is already. You can remove it.

You probably don’t need this anymore if you’re only running a single Caddy instance. This makes Caddy act as an ACME server, but if you’re not using this Caddy instance as a certificate authority to issue certs for other servers, you don’t need this.

1 Like

@francislavoie , solution above working perfectly.

Now, to go “to production”, I want to put the above “stack” behind my “front Caddy”.

Scenario is this:

port(s) exposed on host               containers
----------------------- -----------------------------------------------
   25/143/465/587/993 - [  mailserver  ]

                        [ phpldapadmin ]
                               |
               80/443 - [    caddy     ] <---> [ nextcloud-web (caddy) ]
                               |
                        [ uptime-kuma  ]

                  636 - [   openldap   ]

Which modifications do I need to do on front Caddy and “Nextcloud Caddy”?

I simple tried to connect front to back, did not worked.

Front Caddy:

nextcloud.cites.aop {
        reverse_proxy https://nextcloud-web
}

“Nextcloud Caddy”

nextcloud-web {
        encode gzip

        redir /.well-known/carddav /remote.php/dav 301
        redir /.well-known/caldav /remote.php/dav 301

        header {
                Strict-Transport-Security max-age=31536000;
        }

        @collabora {
                path /browser/*
                path /hosting/discovery
                path /hosting/capabilities
                path /cool/*
        }

        reverse_proxy @collabora https://nextcloud-collabora:9980 {
                transport http {
                        tls_insecure_skip_verify
                }
        }

        @forbidden {
                path /.htaccess
                path /data/*
                path /config/*
                path /db_structure
                path /.xml
                path /README
                path /3rdparty/*
                path /lib/*
                path /templates/*
                path /occ
                path /console.php
        }
        respond @forbidden 404

        root * /var/www/html

        php_fastcgi nextcloud-app:9000

        file_server
}

Just use http:// { here I guess, you don’t need to use the container name nor HTTPS in this situation, since you’re communicating between two containers in a private docker network.

Then just change this to http://nextcloud-web

But having two Caddy instances here might be redundant if they’re both in containers. You could probably just plop the config you have in the backend one into the frontend one, replacing reverse_proxy.

The second one is in the same docker-compose.yml and I think this allows it to access static files from nextcloud-app using that “volumes_from”. I don’t know if this would work from another container not is the same definition (docker-compose.yml).

Right – probably not.

FYI, you’ll likely need to configure trusted_proxies in your backend one as a subdirective of php_fastcgi and the collabora reverse_proxy to trust the X-Forwarded-* headers the front one is sending it:

	reverse_proxy @collabora https://nextcloud-collabora:9980 {
		trusted_proxies private_ranges
		transport http {
			tls_insecure_skip_verify
		}
	}
	php_fastcgi nextcloud-app:9000 {
		trusted_proxies private_ranges
	}

First attempt - no success.

Front Caddy log:

{"level":"debug","ts":1652142602.9753106,"logger":"tls.handshake","msg":"choosing certificate","identifier":"nextcloud.cites.aop","num_choices":1}
{"level":"debug","ts":1652142602.9755774,"logger":"tls.handshake","msg":"default certificate selection results","identifier":"nextcloud.cites.aop","subjects":["nextcloud.cites.aop"],"managed":true,"issuer_key":"acme-v02.api.letsencrypt.org-directory","hash":"0113e5d7dbf84cee3f4619356c0dec2da32fdea6fee71d5112e461062caab0e0"}
{"level":"debug","ts":1652142602.9756305,"logger":"tls.handshake","msg":"matched certificate in cache","subjects":["nextcloud.cites.aop"],"managed":true,"expiration":1659911945,"hash":"0113e5d7dbf84cee3f4619356c0dec2da32fdea6fee71d5112e461062caab0e0"}
{"level":"debug","ts":1652142603.1559646,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"nextcloud-web:80","total_upstreams":1}
{"level":"debug","ts":1652142603.162092,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"nextcloud-web:80","duration":0.005917763,"request":{"remote_ip":"201.21.x.y","remote_port":"57907","proto":"HTTP/2.0","method":"GET","host":"nextcloud.cites.aop","uri":"/","headers":{"Sec-Fetch-Site":["none"],"Sec-Fetch-User":["?1"],"X-Forwarded-For":["201.21.x.y"],"X-Forwarded-Host":["nextcloud.cites.aop"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"],"Accept-Encoding":["gzip, deflate, br"],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-Dest":["document"],"Sec-Fetch-Mode":["navigate"],"X-Forwarded-Proto":["https"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0"],"Te":["trailers"],"Accept-Language":["en-US,en;q=0.8,pt-BR;q=0.5,pt;q=0.3"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"nextcloud.cites.aop"}},"headers":{"Location":["https://nextcloud.cites.aop/"],"Server":["Caddy"],"Date":["Tue, 10 May 2022 00:30:03 GMT"],"Content-Length":["0"]},"status":308}
{"level":"debug","ts":1652142603.3288398,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"nextcloud-web:80","total_upstreams":1}
{"level":"debug","ts":1652142603.3310926,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"nextcloud-web:80","duration":0.002118158,"request":{"remote_ip":"201.21.x.y","remote_port":"57907","proto":"HTTP/2.0","method":"GET","host":"nextcloud.cites.aop","uri":"/","headers":{"X-Forwarded-Host":["nextcloud.cites.aop"],"Te":["trailers"],"Accept-Encoding":["gzip, deflate, br"],"X-Forwarded-For":["201.21.x.y"],"X-Forwarded-Proto":["https"],"Sec-Fetch-Mode":["navigate"],"Sec-Fetch-Site":["none"],"Sec-Fetch-User":["?1"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"],"Accept-Language":["en-US,en;q=0.8,pt-BR;q=0.5,pt;q=0.3"],"Sec-Fetch-Dest":["document"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"nextcloud.cites.aop"}},"headers":{"Date":["Tue, 10 May 2022 00:30:03 GMT"],"Content-Length":["0"],"Location":["https://nextcloud.cites.aop/"],"Server":["Caddy"]},"status":308}
{"level":"debug","ts":1652142603.4967706,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"nextcloud-web:80","total_upstreams":1}
{"level":"debug","ts":1652142603.4985929,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"nextcloud-web:80","duration":0.001710449,"request":{"remote_ip":"201.21.x.y","remote_port":"57907","proto":"HTTP/2.0","method":"GET","host":"nextcloud.cites.aop","uri":"/","headers":{"Sec-Fetch-User":["?1"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0"],"Accept-Language":["en-US,en;q=0.8,pt-BR;q=0.5,pt;q=0.3"],"X-Forwarded-For":["201.21.x.y"],"X-Forwarded-Host":["nextcloud.cites.aop"],"Sec-Fetch-Site":["none"],"Accept-Encoding":["gzip, deflate, br"],"Sec-Fetch-Dest":["document"],"Sec-Fetch-Mode":["navigate"],"Te":["trailers"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"],"X-Forwarded-Proto":["https"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"nextcloud.cites.aop"}},"headers":{"Location":["https://nextcloud.cites.aop/"],"Server":["Caddy"],"Date":["Tue, 10 May 2022 00:30:03 GMT"],"Content-Length":["0"]},"status":308}
{"level":"debug","ts":1652142603.67227,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"nextcloud-web:80","total_upstreams":1}
...
{"level":"debug","ts":1652142605.4051576,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"nextcloud-web:80","duration":0.001706301,"request":{"remote_ip":"201.21.x.y","remote_port":"57907","proto":"HTTP/2.0","method":"GET","host":"nextcloud.cites.aop","uri":"/","headers":{"Accept-Language":["en-US,en;q=0.8,pt-BR;q=0.5,pt;q=0.3"],"Upgrade-Insecure-Requests":["1"],"X-Forwarded-Proto":["https"],"X-Forwarded-Host":["nextcloud.cites.aop"],"Accept-Encoding":["gzip, deflate, br"],"Sec-Fetch-User":["?1"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"],"Sec-Fetch-Mode":["navigate"],"Sec-Fetch-Site":["none"],"X-Forwarded-For":["201.21.x.y"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0"],"Te":["trailers"],"Sec-Fetch-Dest":["document"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"nextcloud.cites.aop"}},"headers":{"Location":["https://nextcloud.cites.aop/"],"Server":["Caddy"],"Date":["Tue, 10 May 2022 00:30:05 GMT"],"Content-Length":["0"]},"status":308}
{"level":"debug","ts":1652142605.5749867,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"nextcloud-web:80","total_upstreams":1}
{"level":"debug","ts":1652142605.57708,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"nextcloud-web:80","duration":0.001848747,"request":{"remote_ip":"201.21.x.y","remote_port":"57907","proto":"HTTP/2.0","method":"GET","host":"nextcloud.cites.aop","uri":"/","headers":{"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0"],"X-Forwarded-For":["201.21.x.y"],"X-Forwarded-Proto":["https"],"X-Forwarded-Host":["nextcloud.cites.aop"],"Accept-Language":["en-US,en;q=0.8,pt-BR;q=0.5,pt;q=0.3"],"Sec-Fetch-Dest":["document"],"Sec-Fetch-Mode":["navigate"],"Te":["trailers"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"],"Upgrade-Insecure-Requests":["1"],"Accept-Encoding":["gzip, deflate, br"],"Sec-Fetch-Site":["none"],"Sec-Fetch-User":["?1"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"nextcloud.cites.aop"}},"headers":{"Date":["Tue, 10 May 2022 00:30:05 GMT"],"Content-Length":["0"],"Location":["https://nextcloud.cites.aop/"],"Server":["Caddy"]},"status":308}
{"level":"debug","ts":1652142605.7499115,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"nextcloud-web:80","total_upstreams":1}
{"level":"debug","ts":1652142605.7517653,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"nextcloud-web:80","duration":0.001659363,"request":{"remote_ip":"201.21.x.y","remote_port":"57907","proto":"HTTP/2.0","method":"GET","host":"nextcloud.cites.aop","uri":"/","headers":{"Te":["trailers"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"],"X-Forwarded-For":["201.21.x.y"],"X-Forwarded-Proto":["https"],"Accept-Language":["en-US,en;q=0.8,pt-BR;q=0.5,pt;q=0.3"],"Accept-Encoding":["gzip, deflate, br"],"Sec-Fetch-Mode":["navigate"],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-Dest":["document"],"Sec-Fetch-Site":["none"],"Sec-Fetch-User":["?1"],"X-Forwarded-Host":["nextcloud.cites.aop"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"nextcloud.cites.aop"}},"headers":{"Location":["https://nextcloud.cites.aop/"],"Server":["Caddy"],"Date":["Tue, 10 May 2022 00:30:05 GMT"],"Content-Length":["0"]},"status":308}
{"level":"debug","ts":1652142605.922193,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"nextcloud-web:80","total_upstreams":1}
{"level":"debug","ts":1652142605.9240024,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"nextcloud-web:80","duration":0.001653683,"request":{"remote_ip":"201.21.x.y","remote_port":"57907","proto":"HTTP/2.0","method":"GET","host":"nextcloud.cites.aop","uri":"/","headers":{"X-Forwarded-Host":["nextcloud.cites.aop"],"Sec-Fetch-Site":["none"],"Sec-Fetch-User":["?1"],"Accept-Language":["en-US,en;q=0.8,pt-BR;q=0.5,pt;q=0.3"],"X-Forwarded-Proto":["https"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0"],"Sec-Fetch-Mode":["navigate"],"Te":["trailers"],"X-Forwarded-For":["201.21.x.y"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"],"Accept-Encoding":["gzip, deflate, br"],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-Dest":["document"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"nextcloud.cites.aop"}},"headers":{"Location":["https://nextcloud.cites.aop/"],"Server":["Caddy"],"Date":["Tue, 10 May 2022 00:30:05 GMT"],"Content-Length":["0"]},"status":308}
{"level":"debug","ts":1652142606.095846,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"nextcloud-web:80","total_upstreams":1}
{"level":"debug","ts":1652142606.0977614,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"nextcloud-web:80","duration":0.001723053,"request":{"remote_ip":"201.21.x.y","remote_port":"57907","proto":"HTTP/2.0","method":"GET","host":"nextcloud.cites.aop","uri":"/","headers":{"X-Forwarded-Host":["nextcloud.cites.aop"],"Sec-Fetch-Mode":["navigate"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"],"Accept-Encoding":["gzip, deflate, br"],"Upgrade-Insecure-Requests":["1"],"X-Forwarded-Proto":["https"],"Sec-Fetch-User":["?1"],"X-Forwarded-For":["201.21.x.y"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0"],"Sec-Fetch-Site":["none"],"Te":["trailers"],"Accept-Language":["en-US,en;q=0.8,pt-BR;q=0.5,pt;q=0.3"],"Sec-Fetch-Dest":["document"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"nextcloud.cites.aop"}},"headers":{"Location":["https://nextcloud.cites.aop/"],"Server":["Caddy"],"Date":["Tue, 10 May 2022 00:30:06 GMT"],"Content-Length":["0"]},"status":308}
{"level":"debug","ts":1652142606.2650433,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"nextcloud-web:80","total_upstreams":1}
{"level":"debug","ts":1652142606.2669764,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"nextcloud-web:80","duration":0.001731158,"request":{"remote_ip":"201.21.x.y","remote_port":"57907","proto":"HTTP/2.0","method":"GET","host":"nextcloud.cites.aop","uri":"/","headers":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"],"Accept-Encoding":["gzip, deflate, br"],"Sec-Fetch-User":["?1"],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-Mode":["navigate"],"X-Forwarded-Proto":["https"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0"],"Accept-Language":["en-US,en;q=0.8,pt-BR;q=0.5,pt;q=0.3"],"Sec-Fetch-Dest":["document"],"Te":["trailers"],"Sec-Fetch-Site":["none"],"X-Forwarded-For":["201.21.x.y"],"X-Forwarded-Host":["nextcloud.cites.aop"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"nextcloud.cites.aop"}},"headers":{"Location":["https://nextcloud.cites.aop/"],"Server":["Caddy"],"Date":["Tue, 10 May 2022 00:30:06 GMT"],"Content-Length":["0"]},"status":308}
{"level":"debug","ts":1652142606.4384348,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"nextcloud-web:80","total_upstreams":1}
{"level":"debug","ts":1652142606.4404645,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"nextcloud-web:80","duration":0.001847344,"request":{"remote_ip":"201.21.x.y","remote_port":"57907","proto":"HTTP/2.0","method":"GET","host":"nextcloud.cites.aop","uri":"/","headers":{"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0"],"Sec-Fetch-Site":["none"],"Sec-Fetch-User":["?1"],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-Dest":["document"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"],"Sec-Fetch-Mode":["navigate"],"Te":["trailers"],"X-Forwarded-For":["201.21.x.y"],"Accept-Language":["en-US,en;q=0.8,pt-BR;q=0.5,pt;q=0.3"],"Accept-Encoding":["gzip, deflate, br"],"X-Forwarded-Proto":["https"],"X-Forwarded-Host":["nextcloud.cites.aop"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"nextcloud.cites.aop"}},"headers":{"Server":["Caddy"],"Date":["Tue, 10 May 2022 00:30:06 GMT"],"Content-Length":["0"],"Location":["https://nextcloud.cites.aop/"]},"status":308}

Back Caddy log (after some time):

{"level":"debug","ts":1652142668.706121,"logger":"tls.obtain","msg":"trying issuer 1/2","issuer":"acme-v02.api.letsencrypt.org-directory"}
{"level":"debug","ts":1652142668.841674,"logger":"tls.issuance.acme.acme_client","msg":"http request","method":"HEAD","url":"https://acme-staging-v02.api.letsencrypt.org/acme/new-nonce","headers":{"User-Agent":["Caddy/2.5.1 CertMagic acmez (linux; amd64)"]},"response_headers":{"Cache-Control":["public, max-age=0, no-cache"],"Date":["Tue, 10 May 2022 00:31:08 GMT"],"Link":["<https://acme-staging-v02.api.letsencrypt.org/directory>;rel=\"index\""],"Replay-Nonce":["0001Gts1xe6wy5Qyk0oZvdcjElOdCX6JKLVbaEtEH9Q_HaE"],"Server":["nginx"],"Strict-Transport-Security":["max-age=604800"],"X-Frame-Options":["DENY"]},"status_code":200}
{"level":"debug","ts":1652142668.897742,"logger":"tls.issuance.acme.acme_client","msg":"http request","method":"POST","url":"https://acme-staging-v02.api.letsencrypt.org/acme/new-order","headers":{"Content-Type":["application/jose+json"],"User-Agent":["Caddy/2.5.1 CertMagic acmez (linux; amd64)"]},"response_headers":{"Boulder-Requester":["53604164"],"Cache-Control":["public, max-age=0, no-cache"],"Content-Length":["192"],"Content-Type":["application/problem+json"],"Date":["Tue, 10 May 2022 00:31:08 GMT"],"Link":["<https://acme-staging-v02.api.letsencrypt.org/directory>;rel=\"index\""],"Replay-Nonce":["0002_zAANtbjAU0ro5UPmyFJSpsmpbNJjSqDR5yD6R2GbsE"],"Server":["nginx"]},"status_code":400}
{"level":"error","ts":1652142668.898085,"logger":"tls.obtain","msg":"could not get certificate from issuer","identifier":"nextcloud-web","issuer":"acme-v02.api.letsencrypt.org-directory","error":"HTTP 400 urn:ietf:params:acme:error:rejectedIdentifier - Error creating new order :: Cannot issue for \"nextcloud-web\": Domain name needs at least one dot"}
{"level":"debug","ts":1652142668.898197,"logger":"tls.obtain","msg":"trying issuer 2/2","issuer":"acme.zerossl.com-v2-DV90"}
{"level":"warn","ts":1652142668.8984134,"logger":"tls.issuance.zerossl","msg":"missing email address for ZeroSSL; it is strongly recommended to set one for next time"}
{"level":"info","ts":1652142669.1824694,"logger":"tls.issuance.zerossl","msg":"generated EAB credentials","key_id":"euwTp1LV4dyx7Be3hzphog"}
{"level":"debug","ts":1652142672.7447736,"logger":"tls.issuance.acme.acme_client","msg":"http request","method":"HEAD","url":"https://acme.zerossl.com/v2/DV90/newNonce","headers":{"User-Agent":["Caddy/2.5.1 CertMagic acmez (linux; amd64)"]},"response_headers":{"Access-Control-Allow-Origin":["*"],"Cache-Control":["max-age=-1"],"Content-Type":["application/octet-stream"],"Date":["Tue, 10 May 2022 00:31:12 GMT"],"Link":["<https://acme.zerossl.com/v2/DV90>;rel=\"index\""],"Replay-Nonce":["ISUVUA7LB0tVIVegkA00lRP_ioxCUzNFOrinyvrM3OA"],"Server":["nginx"],"Strict-Transport-Security":["max-age=15552000"]},"status_code":200}
{"level":"debug","ts":1652142676.2519104,"logger":"tls.issuance.acme.acme_client","msg":"http request","method":"POST","url":"https://acme.zerossl.com/v2/DV90/newAccount","headers":{"Content-Type":["application/jose+json"],"User-Agent":["Caddy/2.5.1 CertMagic acmez (linux; amd64)"]},"response_headers":{"Access-Control-Allow-Origin":["*"],"Cache-Control":["max-age=0, no-cache, no-store","max-age=-1"],"Content-Length":["579"],"Content-Type":["application/json"],"Date":["Tue, 10 May 2022 00:31:16 GMT"],"Location":["https://acme.zerossl.com/v2/DV90/account/euwTp1LV4dyx7Be3hzphog"],"Replay-Nonce":["ntii3nsJu5tQ-5rQsp53xE1j-jbhmjnUuKwOEl0gXN0"],"Server":["nginx"],"Status":[""],"Strict-Transport-Security":["max-age=15552000"]},"status_code":201}
{"level":"debug","ts":1652142679.3436313,"logger":"tls.issuance.acme.acme_client","msg":"http request","method":"POST","url":"https://acme.zerossl.com/v2/DV90/newOrder","headers":{"Content-Type":["application/jose+json"],"User-Agent":["Caddy/2.5.1 CertMagic acmez (linux; amd64)"]},"response_headers":{"Access-Control-Allow-Origin":["*"],"Cache-Control":["max-age=0, no-cache, no-store","max-age=-1"],"Content-Length":["119"],"Content-Type":["application/problem+json"],"Date":["Tue, 10 May 2022 00:31:19 GMT"],"Link":["<https://acme.zerossl.com/v2/DV90>;rel=\"index\""],"Replay-Nonce":["etxVDK11NfdaNXRmd9vJp2Y-1zet_Xs6s9DGBS0upgQ"],"Server":["nginx"]},"status_code":400}
{"level":"error","ts":1652142679.3438034,"logger":"tls.obtain","msg":"could not get certificate from issuer","identifier":"nextcloud-web","issuer":"acme.zerossl.com-v2-DV90","error":"HTTP 400 urn:ietf:params:acme:error:rejectedIdentifier - Invalid DNS identifier [nextcloud-web]"}
{"level":"error","ts":1652142679.3438241,"logger":"tls.obtain","msg":"will retry","error":"[nextcloud-web] Obtain: [nextcloud-web] creating new order: attempt 1: https://acme.zerossl.com/v2/DV90/newOrder: HTTP 400 urn:ietf:params:acme:error:rejectedIdentifier - Invalid DNS identifier [nextcloud-web] (ca=https://acme.zerossl.com/v2/DV90)","attempt":3,"retrying_in":120,"elapsed":216.832123586,"max_duration":2592000}

Front Caddy Caddyfile:

nextcloud.cites.aop {
        reverse_proxy http://nextcloud-web
}

Back Caddy Caddyfile:

nextcloud-web {

        encode gzip

        redir /.well-known/carddav /remote.php/dav 301
        redir /.well-known/caldav /remote.php/dav 301

        header {
                Strict-Transport-Security max-age=31536000;
        }

        @collabora {
                path /browser/*
                path /hosting/discovery
                path /hosting/capabilities
                path /cool/*
        }

        reverse_proxy @collabora https://nextcloud-collabora:9980 {
                trusted_proxies private_ranges
                transport http {
                        tls_insecure_skip_verify
                }
        }

        @forbidden {
                path /.htaccess
                path /data/*
                path /config/*
                path /db_structure
                path /.xml
                path /README
                path /3rdparty/*
                path /lib/*
                path /templates/*
                path /occ
                path /console.php
        }
        respond @forbidden 404

        root * /var/www/html

        php_fastcgi nextcloud-app:9000 {
                trusted_proxies private_ranges
        }

        file_server
}

You haven’t made the changes I suggested… you need to not use nextcloud-web as your site address, that won’t work. Caddy is trying to fetch a certificate from a public ACME issuer because it thinks that’s a real domain.

Also Caddy’s reverse_proxy passes through the Host from the original request, which would be nextcloud.cites.aop. So nextcloud-web as a host matcher wouldn’t work (which is what a site address is, it’s a host matcher, plus an indication to Caddy of what TLS certs it needs)

So, just

{
        debug
}

http:// {
        encode gzip

        redir /.well-known/carddav /remote.php/dav 301
        redir /.well-known/caldav /remote.php/dav 301

        header {
                Strict-Transport-Security max-age=31536000;
        }

        @collabora {
                path /browser/*
                path /hosting/discovery
                path /hosting/capabilities
                path /cool/*
        }

        reverse_proxy @collabora https://nextcloud-collabora:9980 {
                trusted_proxies private_ranges
                transport http {
                        tls_insecure_skip_verify
                }
        }

        @forbidden {
                path /.htaccess
                path /data/*
                path /config/*
                path /db_structure
                path /.xml
                path /README
                path /3rdparty/*
                path /lib/*
                path /templates/*
                path /occ
                path /console.php
        }
        respond @forbidden 404

        root * /var/www/html

        php_fastcgi nextcloud-app:9000 {
                trusted_proxies private_ranges
        }

        file_server
}

on the Caddyfile of the “nextcloud-web” (back Caddy) container?

Yep :+1: that’s correct