Как настроить Caddy с SSL Let’s Encrypt и Duck DNS для обслуживания нескольких сервисов, работающих как контейнеры Docker?

Вопрос или проблема

Мне удалось настроить VaultWarden, доступный только в локальной сети LAN с сертификатом SSL от Let’s Encrypt, используя Caddy. Caddy, VaultWarden и другие службы работают как контейнеры Docker на хосте Raspberry Pi.

Я настроил домен Duck DNS: test111.duckdns.org, который указывает на мой приватный IP-адрес LAN Raspberry Pi.

Я добавил переопределение хоста в настройках DNS-резольвера pfSense (это был ключевой шаг, чтобы это работало) следующим образом:

Host: test111
Domain: duckdns.org
IP Address: <IP-адрес raspberry pi>

Мой файл Docker Compose:

networks:
  docker-mongoose:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: "172.16.117.0/27"

services:
  caddy:
    image: caddy:2
    networks:
      docker-mongoose:
        ipv4_address: 172.16.117.10
    container_name: caddy
    restart: always
    ports:
      - 80:80
      - 443:443
      - 443:443/udp # Нужно для HTTP/3.
    volumes:
      - ./caddy:/usr/bin/caddy  
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - ./caddy-config:/config
      - ./caddy-data:/data
    environment:
      DOMAIN: "test111.duckdns.org" 
      #EMAIL: ""
      DUCKDNS_TOKEN: "<токен duckdns>>"
      LOG_FILE: "/data/access.logs"

   unifi-network-application:
    container_name: unifi-network-application
    image: lscr.io/linuxserver/unifi-network-application:latest
    networks:
      docker-mongoose:
        ipv4_address: 172.16.117.9
    sysctls:
      - net.ipv6.conf.all.disable_ipv6=1
    ports:
      - 8443:8443
      - 3478:3478/udp
      - 10001:10001/udp
      - 8080:8080
      - 1900:1900/udp #по желанию
      #- 8843:8843 #по желанию
      #- 8880:8880 #по желанию
      #- 6789:6789 #по желанию
      #- 5514:5514/udp #по желанию
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/London
      - MONGO_USER=user
      - MONGO_PASS=password
      - MONGO_HOST=unifi-db
      - MONGO_PORT=27017
      - MONGO_DBNAME=unifi-db
      - MEM_LIMIT=1024 #по желанию
      - MEM_STARTUP=1024 #по желанию
      #- MONGO_TLS= #по желанию
      #- MONGO_AUTHSOURCE= #по желанию
    volumes:
      - /home/user/docker/unifi-network-application/config:/config
    restart: unless-stopped

    unifi-db:
      и так далее....

  vaultwarden:
    image: vaultwarden/server:latest
    networks:
      docker-mongoose:
        ipv4_address: 172.16.117.8
    container_name: vaultwarden
    restart: always
    environment:
      DOMAIN: "https://test111.duckdns.org"
      SIGNUPS_ALLOWED: "false"
      INVITATIONS_ALLOWED: "false"
      SHOW_PASSWORD_HINT: "false"
      LOG_FILE: "/data/vaultwarden.log"
      LOG_LEVEL: "warn"
    volumes:
      - ./vw-data:/data # путь перед : можно изменить
    #ports:
      #- 8888:80 # вы можете заменить 11001 на предпочитаемый вами порт

Мой Caddyfile:

{$DOMAIN} {
    log {
        level INFO
        output file {$LOG_FILE} {
            roll_size 10MB
            roll_keep 10
        }
    }

    # Используйте вызов ACME DNS-01, чтобы получить сертификат для настроенного домена.
    tls {
        dns duckdns {$DUCKDNS_TOKEN}
    }

    # Эта настройка может иметь проблемы совместимости с некоторыми браузерами
    # (например, загрузка вложений в Firefox). Попробуйте отключить это,
    # если вы столкнетесь с проблемами.
    encode zstd gzip

    # Проксирование всего на Rocket
    reverse_proxy vaultwarden:80
}

Эта настройка работает, я могу получить доступ к своему VaultWarden через SSL, перейдя по адресу https://test111.duckdns.org, и используется сертификат Let’s Encrypt. Я использовал это руководство, чтобы достичь этого.

Тем не менее, я хотел бы использовать Caddy для нескольких сервисов Docker. Например, чтобы посетить VaultWarden, я мог бы перейти по адресу https://vaultwarden.test111.duckdns.org или https://service.test111.duckdns.org и т.д.

Я попытался изменить это в Caddyfile, используя подстановочные знаки:

# Подстановочный SSL для всех поддоменов под доменом, определенным в переменной {$DOMAIN}
*.{$DOMAIN} {
    tls {
        dns duckdns {$DUCKDNS_TOKEN}
    }

    # Конфигурация журналов (по желанию, изменяйте по необходимости)
    log {
        level INFO
        output file {$LOG_FILE} {
            roll_size 10MB
            roll_keep 10
        }
    }

    # Прокси по умолчанию для общего сервиса, если не совпадает с конкретным сервисом
    reverse_proxy service_default:80
}

# Сервис Vaultwarden
vaultwarden.{$DOMAIN} {
    reverse_proxy vaultwarden:80
    log {
        level INFO
        output file {$LOG_FILE} {
            roll_size 10MB
            roll_keep 10
        }
    }
}

unifi.{$DOMAIN} {
    reverse_proxy unifi-network-application:8443
    log {
        level INFO
        output file {$LOG_FILE} {
            roll_size 10MB
            roll_keep 10
        }
    }
}

Я также добавил переопределения хостов в настройки DNS-резольвера pfSense для различных служб, чтобы указать их на свои IP-адреса Docker:

Host: unifi     
Domain: test111.duckdns.org     
IP Address: 172.16.117.9
Host: vaultwarden   
Domain: test111.duckdns.org     
IP Address: 172.16.117.8

И они могут быть найдены с помощью nslookup:

nslookup vaultwarden.test111.duckdns.org
Server:     127.0.0.53
Address:    127.0.0.53#53

Non-authoritative answer:
Name:   vaultwarden.test111.duckdns.org
Address: 172.16.117.8

Однако это не работает, я не могу получить доступ к своим службам Docker, и я получаю следующие ошибки в своем контейнере Caddy:

{"level":"info","ts":1731770427.407683,"msg":"using config from file","file":"/etc/caddy/Caddyfile"}

{"level":"info","ts":1731770427.4159002,"msg":"adapted config to JSON","adapter":"caddyfile"}

{"level":"info","ts":1731770427.4204524,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//127.0.0.1:2019"]}

{"level":"info","ts":1731770427.4216182,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0x383a900"}

{"level":"info","ts":1731770427.4221516,"logger":"http.auto_https","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":1731770427.4224873,"logger":"http.auto_https","msg":"enabling automatic HTTP->HTTPS redirects","server_name":"srv0"}

{"level":"info","ts":1731770427.4248602,"logger":"http","msg":"enabling HTTP/3 listener","addr":":443"}

{"level":"info","ts":1731770427.4254677,"msg":"failed to sufficiently increase receive buffer size (was: 208 kiB, wanted: 7168 kiB, got: 416 kiB). See https://github.com/quic-go/quic-go/wiki/UDP-Buffer-Sizes for details."}

{"level":"info","ts":1731770427.4263346,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}

{"level":"info","ts":1731770427.4268074,"logger":"http.log","msg":"server running","name":"remaining_auto_https_redirects","protocols":["h1","h2","h3"]}

{"level":"info","ts":1731770427.4269671,"logger":"http","msg":"enabling automatic TLS certificate management","domains":["vaultwarden.test111.duckdns.org","unifi.test111.duckdns.org","*.test111.duckdns.org"]}

{"level":"info","ts":1731770427.4284034,"msg":"autosaved config (load with --resume flag)","file":"/config/caddy/autosave.json"}

{"level":"info","ts":1731770427.4289424,"msg":"serving initial configuration"}

{"level":"info","ts":1731770427.4288747,"logger":"tls.obtain","msg":"acquiring lock","identifier":"vaultwarden.test111.duckdns.org"}

{"level":"info","ts":1731770427.4296653,"logger":"tls.obtain","msg":"acquiring lock","identifier":"unifi.test111.duckdns.org"}

{"level":"info","ts":1731770427.429877,"logger":"tls.obtain","msg":"acquiring lock","identifier":"*.test111.duckdns.org"}

{"level":"info","ts":1731770427.4420304,"logger":"tls","msg":"storage cleaning happened too recently; skipping for now","storage":"FileStorage:/data/caddy","instance":"a16163dc-5a65-4977-a1d2-99f3861efde9","try_again":1731856827.4420183,"try_again_in":86399.999995129}

{"level":"info","ts":1731770427.4445798,"logger":"tls","msg":"finished cleaning storage units"}

{"level":"info","ts":1731770427.44627,"logger":"tls.obtain","msg":"lock acquired","identifier":"*.test111.duckdns.org"}

{"level":"info","ts":1731770427.4462702,"logger":"tls.obtain","msg":"lock acquired","identifier":"vaultwarden.test111.duckdns.org"}

{"level":"info","ts":1731770427.446822,"logger":"tls.obtain","msg":"obtaining certificate","identifier":"*.test111.duckdns.org"}

{"level":"info","ts":1731770427.4474423,"logger":"tls.obtain","msg":"obtaining certificate","identifier":"vaultwarden.test111.duckdns.org"}

{"level":"info","ts":1731770427.4468448,"logger":"tls.obtain","msg":"lock acquired","identifier":"unifi.test111.duckdns.org"}

{"level":"info","ts":1731770427.4486356,"logger":"tls.obtain","msg":"obtaining certificate","identifier":"unifi.test111.duckdns.org"}

{"level":"info","ts":1731770427.4698937,"logger":"tls","msg":"waiting on internal rate limiter","identifiers":["unifi.test111.duckdns.org"],"ca":"https://acme-v02.api.letsencrypt.org/directory","account":""}

{"level":"info","ts":1731770427.4699652,"logger":"tls","msg":"done waiting on internal rate limiter","identifiers":["unifi.test111.duckdns.org"],"ca":"https://acme-v02.api.letsencrypt.org/directory","account":""}

{"level":"info","ts":1731770427.4700146,"logger":"tls","msg":"using ACME account","account_id":"https://acme-v02.api.letsencrypt.org/acme/acct/1972895377","account_contact":[]}

{"level":"info","ts":1731770427.4704852,"logger":"tls","msg":"waiting on internal rate limiter","identifiers":["vaultwarden.test111.duckdns.org"],"ca":"https://acme-v02.api.letsencrypt.org/directory","account":""}

{"level":"info","ts":1731770427.4709487,"logger":"tls","msg":"done waiting on internal rate limiter","identifiers":["vaultwarden.test111.duckdns.org"],"ca":"https://acme-v02.api.letsencrypt.org/directory","account":""}

{"level":"info","ts":1731770427.472356,"logger":"tls","msg":"using ACME account","account_id":"https://acme-v02.api.letsencrypt.org/acme/acct/1972895377","account_contact":[]}

{"level":"info","ts":1731770427.4715934,"logger":"tls.issuance.acme","msg":"waiting on internal rate limiter","identifiers":["*.test111.duckdns.org"],"ca":"https://acme-v02.api.letsencrypt.org/directory","account":""}

{"level":"info","ts":1731770427.4725082,"logger":"tls.issuance.acme","msg":"done waiting on internal rate limiter","identifiers":["*.test111.duckdns.org"],"ca":"https://acme-v02.api.letsencrypt.org/directory","account":""}

{"level":"info","ts":1731770427.4725654,"logger":"tls.issuance.acme","msg":"using ACME account","account_id":"https://acme-v02.api.letsencrypt.org/acme/acct/1972895377","account_contact":[]}

{"level":"info","ts":1731770428.6145887,"logger":"tls.acme_client","msg":"trying to solve challenge","identifier":"vaultwarden.test111.duckdns.org","challenge_type":"tls-alpn-01","ca":"https://acme-v02.api.letsencrypt.org/directory"}

{"level":"info","ts":1731770428.686017,"logger":"tls.acme_client","msg":"trying to solve challenge","identifier":"unifi.test111.duckdns.org","challenge_type":"tls-alpn-01","ca":"https://acme-v02.api.letsencrypt.org/directory"}

{"level":"info","ts":1731770428.8439467,"logger":"tls.issuance.acme.acme_client","msg":"trying to solve challenge","identifier":"*.test111.duckdns.org","challenge_type":"dns-01","ca":"https://acme-v02.api.letsencrypt.org/directory"}

{"level":"error","ts":1731770429.2492373,"logger":"tls.acme_client","msg":"challenge failed","identifier":"unifi.test111.duckdns.org","challenge_type":"tls-alpn-01","problem":{"type":"urn:ietf:params:acme:error:dns","title":"","detail":"no valid A records found for unifi.test111.duckdns.org; DNS problem: SERVFAIL looking up AAAA for unifi.test111.duckdns.org - the domain's nameservers may be malfunctioning","instance":"","subproblems":[]}}

{"level":"error","ts":1731770429.2495832,"logger":"tls.acme_client","msg":"validating authorization","identifier":"unifi.test111.duckdns.org","problem":{"type":"urn:ietf:params:acme:error:dns","title":"","detail":"no valid A records found for unifi.test111.duckdns.org; DNS problem: SERVFAIL looking up AAAA for unifi.test111.duckdns.org - the domain's nameservers may be malfunctioning","instance":"","subproblems":[]},"order":"https://acme-v02.api.letsencrypt.org/acme/order/1972895377/323713330197","attempt":1,"max_attempts":3}

{"level":"info","ts":1731770430.672126,"logger":"tls.acme_client","msg":"trying to solve challenge","identifier":"unifi.test111.duckdns.org","challenge_type":"http-01","ca":"https://acme-v02.api.letsencrypt.org/directory"}

{"level":"error","ts":1731770431.3256845,"logger":"tls.issuance.acme.acme_client","msg":"cleaning up solver","identifier":"*.test111.duckdns.org","challenge_type":"dns-01","error":"no memory of presenting a DNS record for \"_acme-challenge.test111.duckdns.org\" (usually OK if presenting also failed)"}

{"level":"error","ts":1731770431.5020833,"logger":"tls.obtain","msg":"could not get certificate from issuer","identifier":"*.test111.duckdns.org","issuer":"acme-v02.api.letsencrypt.org-directory","error":"[*.test111.duckdns.org] solving challenges: presenting for challenge: could not determine zone for domain \"_acme-challenge.test111.duckdns.org\": unexpected response code 'SERVFAIL' for _acme-challenge.test111.duckdns.org. (order=https://acme-v02.api.letsencrypt.org/acme/order/1972895377/323713330907) (ca=https://acme-v02.api.letsencrypt.org/directory)"}

{"level":"error","ts":1731770431.5025475,"logger":"tls.obtain","msg":"will retry","error":"[*.test111.duckdns.org] Obtain: [*.test111.duckdns.org] solving challenges: presenting for challenge: could not determine zone for domain \"_acme-challenge.test111.duckdns.org\": unexpected response code 'SERVFAIL' for _acme-challenge.test111.duckdns.org. (order=https://acme-v02.api.letsencrypt.org/acme/order/1972895377/323713330907) (ca=https://acme-v02.api.letsencrypt.org/directory)","attempt":1,"retrying_in":60,"elapsed":4.05621756,"max_duration":2592000}

{"level":"error","ts":1731770438.8788044,"logger":"tls.acme_client","msg":"challenge failed","identifier":"vaultwarden.test111.duckdns.org","challenge_type":"http-01","problem":{"type":"urn:ietf:params:acme:error:dns","title":"","detail":"DNS problem: SERVFAIL looking up A for vaultwarden.test111.duckdns.org - the domain's nameservers may be malfunctioning; no valid AAAA records found for vaultwarden.test111.duckdns.org","instance":"","subproblems":[]}}

{"level":"error","ts":1731770438.8789387,"logger":"tls.acme_client","msg":"validating authorization","identifier":"vaultwarden.test111.duckdns.org","problem":{"type":"urn:ietf:params:acme:error:dns","title":"","detail":"DNS problem: SERVFAIL looking up A for vaultwarden.test111.duckdns.org - the domain's nameservers may be malfunctioning; no valid AAAA records found for vaultwarden.test111.duckdns.org","instance":"","subproblems":[]},"order":"https://acme-v02.api.letsencrypt.org/acme/order/1972895377/323713330097","attempt":1,"max_attempts":3}

{"level":"info","ts":1731770440.2944498,"logger":"tls.acme_client","msg":"trying to solve challenge","identifier":"vaultwarden.test111.duckdns.org","challenge_type":"http-01","ca":"https://acme-v02.api.letsencrypt.org/directory"}

{"level":"error","ts":1731770450.1866465,"logger":"tls.acme_client","msg":"challenge failed","identifier":"unifi.test111.duckdns.org","challenge_type":"http-01","problem":{"type":"urn:ietf:params:acme:error:dns","title":"","detail":"no valid A records found for unifi.test111.duckdns.org; no valid AAAA records found for unifi.test111.duckdns.org","instance":"","subproblems":[]}}

{"level":"error","ts":1731770450.1867352,"logger":"tls.acme_client","msg":"validating authorization","identifier":"unifi.test111.duckdns.org","problem":{"type":"urn:ietf:params:acme:error:dns","title":"","detail":"no valid A records found for unifi.test111.duckdns.org; no valid AAAA records found for unifi.test111.duckdns.org","instance":"","subproblems":[]},"order":"https://acme-v02.api.letsencrypt.org/acme/order/1972895377/323713337107","attempt":2,"max_attempts":3}

{"level":"error","ts":1731770450.1868649,"logger":"tls.obtain","msg":"could not get certificate from issuer","identifier":"unifi.test111.duckdns.org","issuer":"acme-v02.api.letsencrypt.org-directory","error":"HTTP 400 urn:ietf:params:acme:error:dns - no valid A records found for unifi.test111.duckdns.org; no valid AAAA records found for unifi.test111.duckdns.org"}

{"level":"error","ts":1731770450.1870203,"logger":"tls.obtain","msg":"will retry","error":"[unifi.test111.duckdns.org] Obtain: [unifi.test111.duckdns.org] solving challenge: unifi.test111.duckdns.org: [unifi.test111.duckdns.org] authorization failed: HTTP 400 urn:ietf:params:acme:error:dns - no valid A records found for unifi.test111.duckdns.org; no valid AAAA records found for unifi.test111.duckdns.org (ca=https://acme-v02.api.letsencrypt.org/directory)","attempt":1,"retrying_in":60,"elapsed":22.738644345,"max_duration":2592000}

{"level":"error","ts":1731770460.5871239,"logger":"tls.acme_client","msg":"challenge failed","identifier":"vaultwarden.test111.duckdns.org","challenge_type":"http-01","problem":{"type":"urn:ietf:params:acme:error:dns","title":"","detail":"DNS problem: SERVFAIL looking up A for vaultwarden.test111.duckdns.org - the domain's nameservers may be malfunctioning; DNS problem: SERVFAIL looking up AAAA for vaultwarden.test111.duckdns.org - the domain's nameservers may be malfunctioning","instance":"","subproblems":[]}}

{"level":"error","ts":1731770460.5872557,"logger":"tls.acme_client","msg":"validating authorization","identifier":"vaultwarden.test111.duckdns.org","problem":{"type":"urn:ietf:params:acme:error:dns","title":"","detail":"DNS problem: SERVFAIL looking up A for vaultwarden.test111.duckdns.org - the domain's nameservers may be malfunctioning; DNS problem: SERVFAIL looking up AAAA for vaultwarden.test111.duckdns.org - the domain's nameservers may be malfunctioning","instance":"","subproblems":[]},"order":"https://acme-v02.api.letsencrypt.org/acme/order/1972895377/323713378127","attempt":2,"max_attempts":3}

{"level":"error","ts":1731770460.5873518,"logger":"tls.obtain","msg":"could not get certificate from issuer","identifier":"vaultwarden.test111.duckdns.org","issuer":"acme-v02.api.letsencrypt.org-directory","error":"HTTP 400 urn:ietf:params:acme:error:dns - DNS problem: SERVFAIL looking up A for vaultwarden.test111.duckdns.org - the domain's nameservers may be malfunctioning; DNS problem: SERVFAIL looking up AAAA for vaultwarden.test111.duckdns.org - the domain's nameservers may be malfunctioning"}

{"level":"error","ts":1731770460.5875442,"logger":"tls.obtain","msg":"will retry","error":"[vaultwarden.test111.duckdns.org] Obtain: [vaultwarden.test111.duckdns.org] solving challenge: vaultwarden.test111.duckdns.org: [vaultwarden.test111.duckdns.org] authorization failed: HTTP 400 urn:ietf:params:acme:error:dns - DNS problem: SERVFAIL looking up A for vaultwarden.test111.duckdns.org - the domain's nameservers may be malfunctioning; DNS problem: SERVFAIL looking up AAAA for vaultwarden.test111.duckdns.org - the domain's nameservers may be malfunctioning (ca=https://acme-v02.api.letsencrypt.org/directory)","attempt":1,"retrying_in":60,"elapsed":33.140588664,"max_duration":2592000}

Я, по сути, пытаюсь достигнуть этого, но с Caddy и duck dns. Но я не уверен, возможно ли это или я неправильно настраиваю Caddy.

Ответ или решение

Настройка Caddy с SSL Let’s Encrypt и Duck DNS для обслуживания нескольких сервисов в контейнерах Docker на Raspberry Pi

Ваша задача заключается в том, чтобы настроить веб-сервер Caddy с поддержкой шифрования SSL от Let’s Encrypt и использованием Duck DNS для управления доменными именами, чтобы обслуживать несколько сервисов, работающих в контейнерах Docker на Raspberry Pi. В рамках данной инструкции я подробно рассмотрю ключевые шаги, которые помогут вам правильно настроить систему.

1. Установка необходимых компонентов

Перед началом убедитесь, что ваш Raspberry Pi обновлен и у вас установлен Docker и Docker Compose. Если они не установлены, выполните следующие команды:

sudo apt update
sudo apt install docker-compose

2. Подготовка Duck DNS

Уже есть настроенный домен test111.duckdns.org, который указывает на локальный IP-адрес Raspberry Pi. Убедитесь, что ваш Duck DNS Token корректен и сохранен в файле вашего Docker Compose.

3. Настройка pfSense

Как вы уже сделали, убедитесь, что в DNS-резолвер pfSense добавлены все необходимые записи для разных сервисов. Это необходимо для правильной маршрутизации:

Host: unifi
Domain: test111.duckdns.org
IP Address: 172.16.117.9

Host: vaultwarden
Domain: test111.duckdns.org
IP Address: 172.16.117.8

4. Docker Compose Файл

Ваш файл docker-compose.yml можно немного улучшить для более четкого разделения конфигурации. Несколько изменений позволяют сделать настройки более понятными:

version: '3.8'

networks:
  docker-mongoose:
    driver: bridge
    ipam:
      config:
        - subnet: "172.16.117.0/27"

services:
  caddy:
    image: caddy:2
    networks:
      docker-mongoose:
        ipv4_address: 172.16.117.10
    container_name: caddy
    restart: always
    ports:
      - 80:80
      - 443:443
      - 443:443/udp
    volumes:
      - ./caddy:/usr/bin/caddy  
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - ./caddy-config:/config
      - ./caddy-data:/data
    environment:
      DOMAIN: "test111.duckdns.org" 
      DUCKDNS_TOKEN: "<duckdns token>"
      LOG_FILE: "/data/access.logs"

  vaultwarden:
    image: vaultwarden/server:latest
    networks:
      docker-mongoose:
        ipv4_address: 172.16.117.8
    container_name: vaultwarden
    restart: always
    environment:
      DOMAIN: "https://vaultwarden.test111.duckdns.org"
    volumes:
      - ./vw-data:/data

  unifi:
    container_name: unifi-network-application
    image: lscr.io/linuxserver/unifi-network-application:latest
    networks:
      docker-mongoose:
        ipv4_address: 172.16.117.9
    restart: unless-stopped
    environment:
      TZ: Europe/London
    volumes:
      - /home/user/docker/unifi-network-application/config:/config

5. Конфигурация Caddyfile

Ваш Caddyfile не совсем корректен для обработки нескольких поддоменов. Правильная конфигурация должна выглядеть следующим образом:

{$DOMAIN} {
    tls {
        dns duckdns {$DUCKDNS_TOKEN}
    }

    log {
        level INFO
        output file {$LOG_FILE} {
            roll_size 10MB
            roll_keep 10
        }
    }

    # Proxy для VaultWarden
    reverse_proxy vaultwarden:80 {
        header_up Host {http.request.host}
    }

}

vaultwarden.{$DOMAIN} {
    reverse_proxy vaultwarden:80
}

unifi.{$DOMAIN} {
    reverse_proxy unifi-network-application:8443
}

6. Использование Caddy для получения сертификатов

Используйте указанные поддомены для последующей настройки. Caddy будет пытаться получить сертификаты от Let’s Encrypt на основе ваших настроек. Убедитесь, что ваши записи A корректно настроены и доступны в интернете — для этого можно воспользоваться утилитами, такими как nslookup.

7. Перезапуск Docker

После внесения всех изменений, перезапустите Docker Compose для применения новых настроек:

docker-compose down
docker-compose up -d

8. Поиск и устранение неполадок

Если возникнут ошибки, проверьте:

  • Логи Caddy на наличие ошибок.
  • Конфигурацию DNS и доступность поддоменов.
  • Убедитесь, что выбранный вами DNS-сервер отображает правильные A-записи.

Заключение

С помощью этого руководства вы сможете настроить Caddy с Let’s Encrypt и Duck DNS для маршрутизации различных сервисов в докер-контейнерах. Это не только послужит повышению безопасности ваших сервисов, но и улучшит их доступность через удобные поддомены. Не забывайте регулярно просматривать логи и обновлять ваш Docker и его компоненты для обеспечения стабильной работы.

Оцените материал
Добавить комментарий

Капча загружается...