Rozdíly
Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.
Obě strany předchozí revize Předchozí verze Následující verze | Předchozí verze | ||
it:server:traefik-reverzni-proxy [2025/01/03 20:02] – [Gitea] Petr Nosek | it:server:traefik-reverzni-proxy [2025/01/15 00:01] (aktuální) – [Zabezpečení Gitea a přihlašování bez hesla] Petr Nosek | ||
---|---|---|---|
Řádek 1076: | Řádek 1076: | ||
Tím jsem dosáhl pohodlného přihlašování bez opakovaného zadávání hesla. | Tím jsem dosáhl pohodlného přihlašování bez opakovaného zadávání hesla. | ||
+ | |||
+ | |||
+ | ===== Zabezpečení Solar Assistanta na portu 80 přes Traefik ===== | ||
+ | |||
+ | Potřeboval jsem zabezpečit Solar Assistanta, který běží na Raspberry Pi na portu 80, a rozhodl jsem se k tomu využít Traefik. Vytvořil jsem tunel pomocí `autossh` ze serveru, na kterém běží Traefik. | ||
+ | |||
+ | SSH tunel je šifrovaný a web Solar Assistanta byl po propojení dostupný na adrese `localhost: | ||
+ | |||
+ | V tomto případě se konfigurace odehrává pomocí labelů u kontejneru Traefik, protože se nebude přistupovat do jiného kontejneru. | ||
+ | |||
+ | ==== Konfigurace Docker Compose ==== | ||
+ | |||
+ | <code yaml> | ||
+ | proxy: | ||
+ | image: traefik | ||
+ | restart: always | ||
+ | container_name: | ||
+ | ports: | ||
+ | - " | ||
+ | - " | ||
+ | extra_hosts: | ||
+ | - " | ||
+ | environment: | ||
+ | - CLOUDFLARE_EMAIL=${CLOUDFLARE_EMAIL} | ||
+ | - CLOUDFLARE_DNS_API_TOKEN=${CLOUDFLARE_DNS_API_TOKEN} | ||
+ | - LETSENCRYPT_EMAIL=${LETSENCRYPT_EMAIL} | ||
+ | volumes: | ||
+ | - ${VOLUME_PATH}/ | ||
+ | - ${VOLUME_PATH}/ | ||
+ | - / | ||
+ | - ./ | ||
+ | - ./ | ||
+ | labels: | ||
+ | traefik.enable: | ||
+ | |||
+ | # Přesměrování HTTP na HTTPS | ||
+ | traefik.http.routers.solar-insecure.rule: | ||
+ | traefik.http.routers.solar-insecure.entrypoints: | ||
+ | traefik.http.routers.solar-insecure.middlewares: | ||
+ | |||
+ | # Middleware pro přesměrování na HTTPS | ||
+ | traefik.http.middlewares.redirect.redirectscheme.scheme: | ||
+ | |||
+ | # HTTPS router | ||
+ | traefik.http.routers.solar.rule: | ||
+ | traefik.http.routers.solar.entrypoints: | ||
+ | traefik.http.routers.solar.tls.certresolver: | ||
+ | traefik.http.routers.solar.service: | ||
+ | </ | ||
+ | |||
+ | ==== Dynamická konfigurace ==== | ||
+ | |||
+ | Do `docker-compose.yml` jsem musel přidat odkaz na dynamické nastavení: | ||
+ | <code yaml> | ||
+ | traefik.http.routers.solar.service: | ||
+ | </ | ||
+ | |||
+ | Soubor `traefik.yml` jsem upravil takto: | ||
+ | <code yaml> | ||
+ | providers: | ||
+ | docker: | ||
+ | exposedByDefault: | ||
+ | file: | ||
+ | directory: "/ | ||
+ | watch: true # Sleduje změny v souboru | ||
+ | </ | ||
+ | |||
+ | Ve složce `traefik-dynamic-config` se nachází soubor `dynamic-config.yml`: | ||
+ | <code yaml> | ||
+ | http: | ||
+ | services: | ||
+ | solar: | ||
+ | loadBalancer: | ||
+ | servers: | ||
+ | - url: " | ||
+ | </ | ||
+ | |||
+ | ==== Postup konfigurace ==== | ||
+ | |||
+ | 1. Musel jsem připravit dynamickou konfiguraci a přidat složku: | ||
+ | < | ||
+ | ./ | ||
+ | </ | ||
+ | Docker neumí pracovat se změnami, pokud je definován pouze soubor – je třeba nasměrovat na celou složku. | ||
+ | |||
+ | 2. Změna se projeví bez restartu Traefiku díky nastavení `watch: true`. | ||
+ | |||
+ | 3. Původně jsem se snažil nadefinovat přesměrování přímo v `docker-compose.yml`, | ||
+ | |||
+ | 4. Nasledováním rady z [[https:// | ||
+ | |||
+ | Dokud jsem nepřesunul nastavení do dynamického konfiguračního souboru, konfigurace nefungovala. | ||
+ | |||
+ | |||
===== Shrnutí a závěrečná konfigurace ===== | ===== Shrnutí a závěrečná konfigurace ===== | ||
Řádek 1106: | Řádek 1200: | ||
- " | - " | ||
- " | - " | ||
+ | extra_hosts: | ||
+ | - " | ||
environment: | environment: | ||
- CLOUDFLARE_EMAIL=${CLOUDFLARE_EMAIL} | - CLOUDFLARE_EMAIL=${CLOUDFLARE_EMAIL} | ||
Řádek 1115: | Řádek 1211: | ||
- / | - / | ||
- ./ | - ./ | ||
+ | - ./ | ||
+ | labels: | ||
+ | traefik.enable: | ||
+ | |||
+ | # Redirect HTTP to HTTPS | ||
+ | traefik.http.routers.solar-insecure.rule: | ||
+ | traefik.http.routers.solar-insecure.entrypoints: | ||
+ | traefik.http.routers.solar-insecure.middlewares: | ||
+ | |||
+ | # Middleware for HTTPS redirection | ||
+ | traefik.http.middlewares.redirect.redirectscheme.scheme: | ||
+ | |||
+ | # HTTPS router | ||
+ | traefik.http.routers.solar.rule: | ||
+ | traefik.http.routers.solar.entrypoints: | ||
+ | traefik.http.routers.solar.tls.certresolver: | ||
+ | traefik.http.routers.solar.service: | ||
+ | |||
+ | |||
postgres: | postgres: | ||
Řádek 1132: | Řádek 1247: | ||
restart: always | restart: always | ||
volumes: | volumes: | ||
- | - ${VOLUME_PATH}/ | + | - ${VOLUME_PATH}/ |
labels: | labels: | ||
traefik.enable: | traefik.enable: | ||
+ | | ||
# Redirect HTTP to HTTPS | # Redirect HTTP to HTTPS | ||
traefik.http.routers.smarthome-insecure.rule: | traefik.http.routers.smarthome-insecure.rule: | ||
Řádek 1193: | Řádek 1308: | ||
- | nodered: | + | |
- | | + | container_name: |
- | | + | build: |
- | | + | context: ${IOT_STACK}/ |
- | | + | args: |
- | | + | - DOCKERHUB_TAG=latest |
- | | + | - EXTRA_PACKAGES=ffmpeg |
- | | + | restart: unless-stopped |
- | | + | user: " |
- | | + | environment: |
- | | + | - TZ=${DOCKER_TZ} |
- | | + | volumes: |
- | | + | - ${VOLUME_PATH}/ |
- | | + | - ${VOLUME_PATH}/ |
- | | + | - / |
- | | + | - / |
- | | + | devices: |
- | | + | - "/ |
- | | + | - "/ |
- | | + | - "/ |
- | | + | labels: |
- | | + | traefik.enable: |
- | # Přesměrování HTTP na HTTPS | + | |
- | | + | traefik.http.routers.nodered-insecure.rule: |
- | | + | traefik.http.routers.nodered-insecure.entrypoints: |
- | | + | traefik.http.routers.nodered-insecure.middlewares: |
- | # Middleware pro přesměrování na HTTPS | + | |
- | | + | traefik.http.middlewares.redirect.redirectscheme.scheme: |
- | # HTTPS konfigurace | + | |
- | | + | traefik.http.routers.nodered.rule: |
- | | + | traefik.http.routers.nodered.entrypoints: |
- | | + | traefik.http.routers.nodered.tls.certresolver: |
- | | + | traefik.http.services.nodered.loadbalancer.server.port: |
- | grafana: | + | |
- | | + | container_name: |
- | | + | image: grafana/ |
- | | + | restart: unless-stopped |
- | | + | user: " |
- | | + | environment: |
- | | + | - TZ=${DOCKER_TZ} |
- | | + | - GF_PATHS_DATA=/ |
- | | + | - GF_PATHS_LOGS=/ |
- | | + | - GF_SECURITY_ALLOW_EMBEDDING=true |
- | | + | - GF_AUTH_ANONYMOUS_ENABLED=true |
- | | + | - GF_AUTH_ANONYMOUS_ORG_NAME=Hajany |
- | | + | - GF_AUTH_ANONYMOUS_ORG_ROLE=Viewer |
- | | + | - GF_SECURITY_HIDE_VERSION=true |
- | | + | volumes: |
- | | + | - ${VOLUME_PATH}/ |
- | | + | - ${VOLUME_PATH}/ |
- | | + | healthcheck: |
- | | + | test: [" |
- | | + | interval: 30s |
- | | + | timeout: 10s |
- | | + | retries: 3 |
- | | + | start_period: |
- | | + | labels: |
- | | + | traefik.enable: |
- | # Redirect HTTP to HTTPS | + | |
- | | + | traefik.http.routers.grafana-insecure.rule: |
- | | + | traefik.http.routers.grafana-insecure.entrypoints: |
- | | + | traefik.http.routers.grafana-insecure.middlewares: |
- | # Middleware for HTTPS redirection | + | |
- | | + | traefik.http.middlewares.redirect.redirectscheme.scheme: |
- | # HTTPS router | + | |
- | | + | traefik.http.routers.grafana.rule: |
- | | + | traefik.http.routers.grafana.entrypoints: |
- | | + | traefik.http.routers.grafana.tls.certresolver: |
- | # Define service port | + | |
- | | + | traefik.http.services.grafana.loadbalancer.server.port: |
- | | + | teslamate: |
- | | + | container_name: |
- | build: | + | image: teslamate/ |
- | context: ${IOT_STACK}/ | + | |
- | args: | + | environment: |
- | | + | - ENCRYPTION_KEY=${TM_ENCRYPTION_KEY} |
- | | + | - DATABASE_USER=${TM_DB_USER} |
- | restart: unless-stopped | + | - DATABASE_PASS=${TM_DB_PASSWORD} |
- | user: " | + | - DATABASE_NAME=${TM_DB} |
- | environment: | + | - DATABASE_HOST=postgres |
- | | + | - VIRTUAL_HOST=${FQDN_TESLAMATE} |
- | volumes: | + | #- MQTT_HOST=mosquitto |
- | | + | - MQTT_HOST=${MAJORDOMUS_MQTT_HOST} |
- | | + | - MQTT_PORT=${MAJORDOMUS_MQTT_PORT} |
- | | + | - MQTT_USERNAME=${MAJORDOMUS_MQTT_USERNAME} |
- | | + | - MQTT_PASSWORD=${MAJORDOMUS_MQTT_PASSWORD} |
- | devices: | + | - MQTT_TLS=true |
- | - "/ | + | - MQTT_TLS_ACCEPT_INVALID_CERTS=true |
- | | + | - TZ=${DOCKER_TZ} |
- | - "/dev/ | + | # |
- | | + | # |
- | | + | labels: |
+ | traefik.enable: | ||
- | # Přesměrování | + | |
- | | + | traefik.http.routers.teslamate-insecure.rule: |
- | | + | traefik.http.routers.teslamate-insecure.entrypoints: |
- | | + | traefik.http.routers.teslamate-insecure.middlewares: |
- | # Middleware pro přesměrování na HTTPS | + | |
- | | + | traefik.http.middlewares.redirect.redirectscheme.scheme: |
- | # HTTPS konfigurace | + | |
- | traefik.http.routers.nodered.rule: " | + | traefik.http.routers.teslamate-ws.entrypoints: |
- | | + | traefik.http.routers.teslamate-ws.tls: "" |
- | | + | |
- | | + | |
- | | + | traefik.http.routers.teslamate.middlewares: " |
- | | + | |
- | | + | |
- | | + | traefik.http.routers.teslamate.tls.certresolver: "tmdnschallenge" |
- | user: "0" | + | traefik.http.services.teslamate.loadbalancer.server.port: "4000" |
- | | + | |
- | - TZ=${DOCKER_TZ} | + | |
- | - GF_PATHS_DATA=/ | + | |
- | - GF_PATHS_LOGS=/ | + | |
- | - GF_SECURITY_ALLOW_EMBEDDING=true | + | |
- | - GF_AUTH_ANONYMOUS_ENABLED=true | + | |
- | - GF_AUTH_ANONYMOUS_ORG_NAME=Hajany | + | |
- | - GF_AUTH_ANONYMOUS_ORG_ROLE=Viewer | + | |
- | - GF_SECURITY_HIDE_VERSION=true | + | |
- | | + | |
- | - ${VOLUME_PATH}/ | + | |
- | - ${VOLUME_PATH}/ | + | |
- | | + | |
- | test: ["CMD", " | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | # Redirect HTTP to HTTPS | ||
- | | ||
- | | ||
- | | ||
- | # Middleware for HTTPS redirection | + | traefik.http.middlewares.teslamate-auth.basicauth.realm: |
- | | + | traefik.http.middlewares.teslamate-auth.basicauth.usersfile: "/ |
- | # HTTPS router | + | |
- | | + | - all |
- | traefik.http.routers.grafana.entrypoints: | + | |
- | | + | |
- | # Define service port | ||
- | | ||
+ | grafana-teslamate: | ||
+ | container_name: | ||
+ | image: teslamate/ | ||
+ | restart: always | ||
+ | environment: | ||
+ | - DATABASE_USER=${TM_DB_USER} | ||
+ | - DATABASE_PASS=${TM_DB_PASSWORD} | ||
+ | - DATABASE_NAME=${TM_DB} | ||
+ | - DATABASE_HOST=postgres | ||
+ | - TZ=${DOCKER_TZ} | ||
+ | - GF_SERVER_DOMAIN=${FQDN_TESLAMATE} | ||
+ | - GF_SERVER_ROOT_URL=%(protocol)s:// | ||
+ | - GF_SERVER_SERVE_FROM_SUB_PATH=true | ||
+ | labels: | ||
+ | # aktivace Traefiku pro tento kontejner | ||
+ | traefik.enable: | ||
- | | + | # Router pro HTTP přesměrování na HTTPS |
- | container_name: | + | |
- | | + | |
- | | + | traefik.http.routers.grafana-teslamate-insecure.middlewares: "redirect" |
- | | + | |
- | | + | |
- | | + | |
- | - " | + | |
- | | + | |
- | - POSTGRES_DB=${NEXTCLOUD_DB} | + | |
- | - POSTGRES_USER=${NEXTCLOUD_DB_USER} | + | |
- | - POSTGRES_PASSWORD=${NEXTCLOUD_DB_PASSWORD} | + | |
- | - POSTGRES_HOST=postgres | + | |
- | - TRUSTED_PROXIES=${TRUSTED_PROXIES} | + | |
- | - OVERWRITEHOST=${FQDN_NEXTCLOUD} | + | |
- | - OVERWRITEPROTOCOL=https | + | |
- | - APACHE_DISABLE_REWRITE_IP=1 | + | |
- | - OVERWRITECLIURL=https: | + | |
- | | + | |
- | - REDIS_HOST_PASSWORD=${REDIS_HOST_PASSWORD} | + | |
- | - PHP_MEMORY_LIMIT=1024M | + | |
- | | + | |
- | - ${NEXTCLOUD_VOLUME_PATH}:/ | + | |
- | - type: tmpfs | + | |
- | | + | |
- | | + | |
- | mode: "1777" | + | |
- | labels: | + | |
- | traefik.enable: "true" | + | |
- | # Redirect | + | |
- | | + | traefik.http.middlewares.redirect.redirectscheme.scheme: "https" |
- | | + | |
- | | + | |
- | # Middleware for HTTPS redirection | + | traefik.http.routers.grafana-teslamate.rule: |
- | | + | traefik.http.routers.grafana-teslamate.entrypoints: |
+ | traefik.http.routers.grafana-teslamate.tls.certresolver: "tmdnschallenge" | ||
+ | traefik.http.services.grafana-teslamate.loadbalancer.server.port: | ||
+ | volumes: | ||
+ | - grafana-teslamate:/ | ||
- | # HTTPS router | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | # Middleware for CalDAV/ | + | redis: |
- | traefik.http.middlewares.nextcloud_redirectregex.redirectregex.permanent: " | + | |
- | traefik.http.middlewares.nextcloud_redirectregex.redirectregex.regex: "https:// | + | image: redis:alpine |
- | traefik.http.middlewares.nextcloud_redirectregex.redirectregex.replacement: "https://$${1}/ | + | restart: always |
+ | | ||
+ | volumes: | ||
+ | - redis-data:/ | ||
- | # Add HSTS header | ||
- | | ||
- | | ||
- | | ||
- | | + | nextcloud: |
+ | container_name: | ||
+ | image: nextcloud: | ||
+ | build: | ||
+ | context: ./ | ||
+ | restart: " | ||
+ | extra_hosts: | ||
+ | - " | ||
+ | environment: | ||
+ | - POSTGRES_DB=${NEXTCLOUD_DB} | ||
+ | - POSTGRES_USER=${NEXTCLOUD_DB_USER} | ||
+ | - POSTGRES_PASSWORD=${NEXTCLOUD_DB_PASSWORD} | ||
+ | - POSTGRES_HOST=postgres | ||
+ | - TRUSTED_PROXIES=${TRUSTED_PROXIES} | ||
+ | - OVERWRITEHOST=${FQDN_NEXTCLOUD} | ||
+ | - OVERWRITEPROTOCOL=https | ||
+ | - APACHE_DISABLE_REWRITE_IP=1 | ||
+ | - OVERWRITECLIURL=https:// | ||
+ | - REDIS_HOST=redis | ||
+ | - REDIS_HOST_PASSWORD=${REDIS_HOST_PASSWORD} | ||
+ | - PHP_MEMORY_LIMIT=1024M | ||
+ | volumes: | ||
+ | - ${NEXTCLOUD_VOLUME_PATH}:/ | ||
+ | - type: tmpfs | ||
+ | target: /tmp | ||
+ | tmpfs: | ||
+ | mode: " | ||
+ | labels: | ||
+ | traefik.enable: | ||
+ | |||
+ | # Redirect HTTP to HTTPS | ||
+ | | ||
+ | traefik.http.routers.nextcloud-insecure.entrypoints: | ||
+ | traefik.http.routers.nextcloud-insecure.middlewares: | ||
+ | |||
+ | # Middleware for HTTPS redirection | ||
+ | traefik.http.middlewares.redirect.redirectscheme.scheme: | ||
+ | |||
+ | # HTTPS router | ||
+ | traefik.http.routers.nextcloud.rule: | ||
+ | traefik.http.routers.nextcloud.entrypoints: | ||
+ | traefik.http.routers.nextcloud.tls.certresolver: | ||
+ | traefik.http.services.nextcloud.loadbalancer.server.port: | ||
+ | |||
+ | # Middleware for CalDAV/ | ||
+ | traefik.http.middlewares.nextcloud_redirectregex.redirectregex.permanent: | ||
+ | traefik.http.middlewares.nextcloud_redirectregex.redirectregex.regex: | ||
+ | traefik.http.middlewares.nextcloud_redirectregex.redirectregex.replacement: | ||
+ | |||
+ | # Add HSTS header | ||
+ | traefik.http.middlewares.nextcloud-hsts.headers.stsSeconds: | ||
+ | traefik.http.middlewares.nextcloud-hsts.headers.stsIncludeSubdomains: | ||
+ | traefik.http.middlewares.nextcloud-hsts.headers.stsPreload: | ||
+ | |||
+ | traefik.http.routers.nextcloud.middlewares: | ||
+ | |||
+ | depends_on: | ||
+ | - postgres | ||
+ | - redis | ||
- | | ||
- | - postgres | ||
- | - redis | ||
gitea: | gitea: | ||
Řádek 1452: | Řádek 1580: | ||
traefik.http.routers.gitea.tls.certresolver: | traefik.http.routers.gitea.tls.certresolver: | ||
traefik.http.services.gitea.loadbalancer.server.port: | traefik.http.services.gitea.loadbalancer.server.port: | ||
+ | |||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | |||
+ | |||
volumes: | volumes: | ||
grafana-teslamate: | grafana-teslamate: | ||
redis-data: | redis-data: | ||
+ | | ||
</ | </ | ||
Řádek 1480: | Řádek 1617: | ||
tmdnschallenge: | tmdnschallenge: | ||
acme: | acme: | ||
- | email: "petr.nosek@gmail.com" | + | email: "mujemail@example.com" |
storage: "/ | storage: "/ | ||
dnsChallenge: | dnsChallenge: | ||
Řádek 1489: | Řádek 1626: | ||
docker: | docker: | ||
exposedByDefault: | exposedByDefault: | ||
+ | file: | ||
+ | directory: "/ | ||
+ | watch: true # Sleduje změny v souboru | ||
global: | global: | ||
Řádek 1499: | Řádek 1639: | ||
maxVersion: VersionTLS12 | maxVersion: VersionTLS12 | ||
sniStrict: true # Zajištění přísného ověřování SNI | sniStrict: true # Zajištění přísného ověřování SNI | ||
+ | </ | ||
+ | Konfigurace **dynamic-config.yml**: | ||
+ | |||
+ | <code yaml> | ||
+ | http: | ||
+ | services: | ||
+ | solar: | ||
+ | loadBalancer: | ||
+ | servers: | ||
+ | - url: " | ||
</ | </ | ||
+ |