I'm using traefik.
On my local machine, by using /etc/hosts, the traefik could handle subdomain very well, but with cloudflare, it is not working.
Here is what happened when I visit http://whoami.ai-tools-online.xyz
local with hosts:
traefik | 172.19.0.1 - - [21/Feb/2023:01:35:46 +0000] "GET / HTTP/1.1" 200 722 "-" "-" 1 "whoami_router@file" "http://whoami:80" 13ms
remote with cloudflare:
traefik | 172.70.222.109 - - [21/Feb/2023:01:31:53 +0000] "GET / HTTP/1.1" 404 19 "-" "-" 13 "-" "-" 3ms
More info:
/etc/hosts:
127.0.0.1 whoami.weloveparty.domain.local
traefik dynamic config:
http:
routers:
whoami_router:
entryPoints:
- web
- websecure
rule: "Host(`whoami.ai-tools-online.xyz`, `whoami.weloveparty.domain.local`)"
service: whoami_service
services:
whoami_service:
loadBalancer:
servers:
- url: http://whoami:80
docker-compose file:
version: "3.9"
services:
traefik:
image: "traefik:v3.0.0-beta2" #"traefik:v2.9.6"
container_name: "traefik"
command:
- "--accesslog=true"
# - "--accessLog.filePath=/tmp/traefik_log.txt"
- "--log.level=DEBUG"
- "--api.insecure=true"
- "--providers.file.directory=/traefik_dynamic_configs"
- "--providers.file.watch=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
ports:
- "80:80"
# - "443:443"
# - "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./configs/traefik_dynamic_configs:/traefik_dynamic_configs" # <== Volume for dynamic conf file
restart: unless-stopped
whoami:
image: "traefik/whoami"
expose: #expose port to other container by using http://whoami:80
- "80"
restart: unless-stopped