Hello!
TL:DR: I get a 404 when running containerized traefik as a proxy before other docker containers serving different domains.
Here is an image of what I want to achive. Is this a good solution for hosting multiple domains on one server or do you generally recommend something else?
My current setup
/srv/acme.json
it contains the necessary info for Let's Encrypt, did a chmod 600 to it
-/srv/traefik.toml
[entryPoints]
[entryPoints.web]
address = ":80"
[entryPoints.web.http.redirections.entryPoint]
to = "websecure"
scheme = "https"
[entryPoints.websecure]
address = ":443"
[api]
dashboard = true
[certificatesResolvers.lets-encrypt.acme]
email = "my@mail.tld"
storage = "acme.json"
[certificatesResolvers.lets-encrypt.acme.tlsChallenge]
[providers.docker]
watch = true
network = "web"
[providers.file]
filename = "traefik_dynamic.toml"
-/srv/traefik_dynamic.toml
[http.middlewares.simpleAuth.basicAuth]
users = [
"user:pw"
]
[http.routers.api]
rule = "Host(`monitor.mydomain.tld`)"
entrypoints = ["websecure"]
middlewares = ["simpleAuth"]
service = "api@internal"
[http.routers.api.tls]
certResolver = "lets-encrypt"
--/srv/lcmp/docker-compose.yml
version: "3.8"
networks:
web:
external: true
internal:
external: false
services:
# PHP Service
php:
build: './php_docker/'
volumes:
- ./www/:/var/www/html/
#labels:
#- traefik.enable=true
#- traefik.http.routers.shop.rule=Host(`mydomain.tld`)
#- traefik.port=443
networks:
- internal
#- web
# Caddy Service
caddy:
build: './caddy_docker/'
depends_on:
- php
restart: unless-stopped
#ports:
# - "80:80"
# - "443:443"
# - "443:443/udp"
volumes:
- ./www/:/var/www/html/
- ./caddy_docker/Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data
- caddy_config:/config
labels:
- traefik.enable=true
- traefik.http.routers.caddy.rule=Host(`mydomain.tld`)
#- traefik.http.routers.caddy.tls=true
#- traefik.http.routers.caddy.tls.certresolver=lets-encrypt
- traefik.port=80
networks:
- internal
- web
# MySQL Service
mysql:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: rootpw
volumes:
- mysqldata:/var/lib/mysql
networks:
- internal
labels:
- traefik.enable=false
# phpMyAdmin Service
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
ports:
- 8080:80
environment:
PMA_HOST: mysql
networks:
- internal
depends_on:
- mysql
# Volumes
volumes:
mysqldata:
caddy_data:
caddy_config:
--/srv/lcmp/caddy_docker
---/srv/lcmp/caddy_docker/Caddyfile
(common) {
header /* {
-Server
}
}
mydomain.tld {
encode gzip zstd
root * /var/www/html/public
php_fastcgi php:9000
file_server
header {
-server
-Link
-X-Powered-By
# disable FLoC tracking
#Permissions-Policy interest-cohort=()
# enable HSTS
Strict-Transport-Security max-age=31536000;
# disable clients from sniffing the media type
X-Content-Type-Options nosniff
# clickjacking protection
X-Frame-Options DENY
# keep referrer data off of HTTP connections
Referrer-Policy no-referrer-when-downgrade
}
}
www.mydomain.tld {
redir https://mydomain.tld{uri}
}
---/srv/lcmp/caddy_docker/Dockerfile
# Use the official Caddy Docker image
FROM caddy:latest
# Update package index and upgrade installed packages
RUN apk update && apk upgrade
# Copy Caddyfile to configure Caddy server
COPY Caddyfile /etc/caddy/Caddyfile
--/srv/lcmp/php_docker
---/srv/lcmp/php_docker/Dockerfile
FROM php:8.2-fpm-alpine
# Downloading install-php-extensions script and making it executable
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
# Making install-php-extensions script executable
RUN chmod +x /usr/local/bin/install-php-extensions
# Installing PHP extensions using install-php-extensions script
RUN install-php-extensions \
mysqli \
pdo \
pdo_mysql \
gd \
zip \
intl \
xml \
curl \
dom \
fileinfo \
iconv \
json \
libxml \
mbstring \
openssl \
pcre \
phar \
simplexml \
zlib
# Setting PHP directives
RUN echo 'memory_limit = 512M' > /usr/local/etc/php/conf.d/memory-limit.ini
RUN echo 'max_execution_time = 300' > /usr/local/etc/php/conf.d/max-execution-time.ini
RUN echo 'max_input_vars = 10000' > /usr/local/etc/php/conf.d/max-input-vars.ini
RUN echo 'max_input_time = 300' > /usr/local/etc/php/conf.d/max-input-time.ini
RUN echo 'opcache.revalidate_freq=0' > /usr/local/etc/php/conf.d/opcache-revalidate-freq.ini
RUN echo 'opcache.validate_timestamps=0' > /usr/local/etc/php/conf.d/opcache-validate-timestamps.ini
RUN echo 'opcache.max_accelerated_files=7963' > /usr/local/etc/php/conf.d/opcache-max-accelerated-files.ini
RUN echo 'opcache.memory_consumption=256' > /usr/local/etc/php/conf.d/opcache-memory-consumption.ini
RUN echo 'opcache.interned_strings_buffer=16' > /usr/local/etc/php/conf.d/opcache-interned-strings-buffer.ini
RUN echo 'opcache.fast_shutdown=1' > /usr/local/etc/php/conf.d/opcache-fast-shutdown.ini
# Cleaning up
RUN rm -rf /var/cache/apk/*
--/srv/lcmp/www
---/srv/lcmp/www/public
Without traefik, just by running the docker-compose.yml in /srv/lcmp and activating the ports in the in the docker-compose.yml in the caddy service section, the website, which is located in /srv/lcmp/www/public ( a Shopware 6 installation)
It's also not clear to me whether to use Let's Encrypt to enable https:// for mydomain.tld or Caddy's built in encryption service, which works flawlessly without the traefik docker container in front of it. The Traefik dashboard works fine with my current setup at monitor.mydomain.tld/dashboard.
The network has been created with this command
docker network create web
The traefik container has been created using this command
docker run -d \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $PWD/traefik.toml:/traefik.toml \
-v $PWD/traefik_dynamic.toml:/traefik_dynamic.toml \
-v $PWD/acme.json:/acme.json \
-p 80:80 \
-p 443:443 \
--network web \
--name traefik \
traefik:v2.2
Here is the output of docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
58e9eb2ad4f2 lcmp-caddy "caddy run --config …" 2 hours ago Up 2 hours 80/tcp, 443/tcp, 2019/tcp, 443/udp lcmp-caddy-1
aa7f81337b50 phpmyadmin/phpmyadmin:latest "/docker-entrypoint.…" 2 hours ago Up 2 hours 0.0.0.0:8080->80/tcp, :::8080->80/tcp lcmp-phpmyadmin-1
e79fc710c52f lcmp-php "docker-php-entrypoi…" 2 hours ago Up 2 hours 9000/tcp lcmp-php-1
f269056c4eb5 mysql:8.0 "docker-entrypoint.s…" 2 hours ago Up 2 hours 3306/tcp, 33060/tcp lcmp-mysql-1
fa29e420f5a1 traefik:v2.2 "/entrypoint.sh trae…" 4 hours ago Up 4 hours 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp traefik
I followed this tutorial, which works when I reproduce it
[How To Use Traefik v2 as a Reverse Proxy for Docker Containers on Ubuntu 20.04 | DigitalOcean](https://Traefik Docker Digital Ocean)