tarim
August 4, 2023, 1:31am
1
I have few applications(frontend, backend api, db and auth). I want to use traefik for reverse proxy to handle all trafik. I created docker-compose file and all my applications are running(different ports), but when I try with my host name, it said 404 page not found. Any suggestion please?
Here is my compose file:
version: '3.9'
services:
db:
image: postgres
restart: unless-stopped
ports:
- "5432:5432"
tty: true
environment:
- POSTGRES_DB=your_database_name
- POSTGRES_USER=your_username
- POSTGRES_PASSWORD=your_password
app:
build:
context: ./app
dockerfile: Dockerfile
ports:
- '9090:5173'
networks:
- web-proxy
volumes:
- ./app:/app
- /app/node_modules
#command: -name web-app
restart: always
labels:
- "traefik.enable=true"
- "traefik.http.routers.app.rule=Host(`app.localhost`)"
depends_on:
- proxy
- api
api:
#container_name: api
build:
context: ./api
dockerfile: Dockerfile
ports:
- "8383:8000"
depends_on:
- proxy
- db
networks:
- web-proxy
#command: -name api
environment:
- DB_HOST=db
- DB_PORT=5432
- DB_NAME=your_database_name
- DB_USER=your_username
- DB_PASSWORD=your_password
labels:
- "traefik.enable=true"
- "traefik.http.routers.api.rule=Host(`api.localhost`)"
proxy:
# The official v2 Traefik docker image
image: traefik:v3.0
networks:
- web-proxy
command:
- --api.dashboard=true
- --log=true
- --log.filePath=/logs/traefik.log
- --log.level=INFO # (Default: error) DEBUG, INFO, WARN, ERROR, FATAL, PANIC
- --accessLog=true
- --accessLog.filePath=/logs/access.log
- --accessLog.bufferingSize=100 # Configuring a buffer of 100 lines
- --accessLog.filters.statusCodes=204-299,400-499,500-599
#- --providers.docker=true
- --api.insecure=true
- --providers.docker
ports:
# The HTTP port
- "80:80"
#- "443:443"
- "8080:8080"
volumes:
# So that Traefik can listen to the Docker events
- /var/run/docker.sock:/var/run/docker.sock
labels:
- traefik.enable=true
networks:
web-proxy:
name: web-proxy
See simple Traefik example .
Add the target service port to the labels. For security do not expose the ports externally (using ports
), but only use Docker network for internal services.
Add docker.network
label when target service is using multiple networks.
Did you create DNS entries for subdomain.localhost
?
tarim
August 7, 2023, 4:56pm
3
I created sub domain names, even I tried the example you provided to me " simple Traefik example". and it said 404 not found as well.
Any suggestion please?
Thank you
Share your Traefik static and dynamic config, and docker-compose.yml
if used.
Check Traefik debug log and dashboard .
you need to use the label with service, like mentioned in example:
- traefik.http.services.mywhoami.loadbalancer.server.port=80
make sure that you are pointing to the correct port
if not work, please share your docker-compose.yml updated again
tarim
August 8, 2023, 5:26pm
6
I tried your example as well. It did not work. and, I don't have dynamic config file.
Thank you,
tarim
August 8, 2023, 5:27pm
7
I tried @bluepuma77 provided example as well. same thing, it did not work.
Thank you,
You don't even have Traefik entrypoints
(listening ports) defined, so it will never work. Check the example, it should have everything you need.
tarim
August 8, 2023, 11:55pm
9
Hello @bluepuma77 ,
I am not sure what are you exactly talking about, but I tried you provided example, and it also did not work as well. your example
tarim
August 9, 2023, 11:35am
10
Hi @sneycampos ,
Here is @bluepuma77 provided example, `version: '3.9'
services:
traefik:
image: traefik:v3.0
ports:
- 80:80
- 443:443
networks:
- proxy
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- letsencrypt:/letsencrypt
#- /var/log:/var/log
command:
- --api.dashboard=true
- --log.level=INFO
#- --log.filepath=/var/log/traefik.log
- --accesslog=true
#- --accesslog.filepath=/var/log/traefik-access.log
- --providers.docker.network=proxy
- --providers.docker.exposedByDefault=false
- --entrypoints.web.address=:80
- --entrypoints.web.http.redirections.entrypoint.to=websecure
- --entryPoints.web.http.redirections.entrypoint.scheme=https
- --entrypoints.websecure.address=:443
- --entrypoints.websecure.asDefault=true
- --entrypoints.websecure.http.tls.certresolver=myresolver
- --certificatesresolvers.myresolver.acme.email=mail@example.com
- --certificatesresolvers.myresolver.acme.tlschallenge=true
- --certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json
labels:
- traefik.enable=true
- traefik.http.routers.mydashboard.rule=Host(traefik.example.com
)
- traefik.http.routers.mydashboard.service=api@internal
- traefik.http.routers.mydashboard.middlewares=myauth
- traefik.http.middlewares.myauth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/
whoami:
image: traefik/whoami:v1.8
networks:
- proxy
labels:
- traefik.enable=true
- traefik.http.routers.mywhoami.rule=Host(whoami.example.com
) || Host(www.whoami.example.com
)
- traefik.http.services.mywhoami.loadbalancer.server.port=80
- traefik.http.middlewares.mywwwredirect.redirectregex.regex=^https://www\.(.*)
- traefik.http.middlewares.mywwwredirect.redirectregex.replacement=https://$${1}
- traefik.http.routers.mywhoami.middlewares=mywwwredirect
networks:
proxy:
name: proxy
volumes:
letsencrypt:
name: letsencrypt`
Please try it.
Thank you,
i tried the example file from link on github and worked fine.
Could you please share your docker-compose.yml again?
Could you format the config correctly, so we can read it?
Use 3 backticks in front and after the code to format it, or select the code and press the </>
button. In YAML every space matters.