I just found traefik a couple days ago, so I'm a little new to this.
I'm trying to set up traefik for a local server on my network that I'm trying to host some things. I particularly want to use it to provide an additional barrier for incoming requests by adding Basic Auth. Since it's basically a headless server I don't have much direct visibility as far as accessing the network directly on the device. However, I've gotten the Quick Start example to work with the Host set to 192.168.0.2
which is the local ip address for my server. The whoami
container loads just fine using ip address 192.168.0.2
until I try to add basic auth. Then it basically just stops loading and I see the browser constantly loading. Here is my docker-compose.yml
:
version: '3'
services:
reverse-proxy:
# The official v3 Traefik docker image
image: traefik:v3.1
# Enables the web UI and tells Traefik to listen to docker
command:
- --api.insecure=true
- --providers.docker
- --accesslog=true
labels:
- "traefik.http.middlewares.auth.basicauth.users=user:$$2y$$05$$t8Yh/MwhO.2GrsvrDSal5uUt5Wv4B20I6rpXsRpAkrUNPukkuPXsC"
ports:
# The HTTP port
- "80:80"
# The Web UI (enabled by --api.insecure=true)
- "8080:8080"
volumes:
# So that Traefik can listen to the Docker events
- /var/run/docker.sock:/var/run/docker.sock
whoami:
# A container that exposes an API to show its IP address
image: traefik/whoami
labels:
- "traefik.http.routers.whoami.rule=Host(`192.168.0.2`)"
- "traefik.http.routers.whoami.middlewares=auth"
The basic auth username and password I generated with the suggested command: echo $(htpasswd -nB user) | sed -e s/\\$/\\$\\$/g
with username user
and password password
.
There are no logs that indicate what happened.
I only see the initial log of the GET request:
10.8.0.6 - - [05/Aug/2024:16:57:27 +0000] "GET / HTTP/1.1" 401 17 "-" "-" 3 "whoami@docker" "-" 0ms
After a while I do get this error:
2024-08-05T17:00:54Z ERR Error while Peeking first byte error="read tcp 192.168.80.3:8080->10.8.0.6:54102: i/o timeout"
I am running this alongside portainer which I will integrate it's container with traefik once I get the basicauth working with traefic. But at the moment, I am not trying to access those docker containers since they do not share a network.
I can also see the middleware being successfully created: