The goal:
- Have traefik ask letsencrypt to generate a wildcard certificate
- Visiting a valid subdomain will use the certificate, and be valid
- Every http call will be redirected to https
- Visiting a non-existant subdomain will show a 404 page, with a valid https cert
The problem:
- Visiting a non-existent subdomain shows traefik's default cert is being served.
Configuration:
commands (docker-compose.yml)
command:
- "--log.level=DEBUG"
- "--providers.docker=true"
- "--providers.docker.network=app_network"
- "--providers.docker.exposedbydefault=false"
- "--providers.file.filename=/etc/traefik/dynamic.yml"
- "--providers.file.watch=true"
- '--entryPoints.http.address=:80'
- '--entryPoints.http.http.redirections.entryPoint.to=https'
- '--entryPoints.http.http.redirections.entryPoint.scheme=https'
- '--entryPoints.http.http.redirections.entryPoint.permanent=true'
- '--entryPoints.https.address=:443'
- '--certificatesresolvers.lets_encrypt_resolver.acme.email=myemail@email.com'
- '--certificatesresolvers.lets_encrypt_resolver.acme.storage=/acme.json'
- '--certificatesresolvers.lets_encrypt_resolver.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory' # @todo remove
- '--certificatesresolvers.lets_encrypt_resolver.acme.dnschallenge=true'
- '--certificatesresolvers.lets_encrypt_resolver.acme.dnschallenge.provider=digitalocean'
- '--certificatesresolvers.lets_encrypt_resolver.acme.dnschallenge.delaybeforecheck=0'
- '--entrypoints.https.http.tls.domains[0].main=mydomain.com'
- '--entrypoints.https.http.tls.domains[0].sans=*.mydomain.com'
- '--entrypoints.https.http.tls.certresolver=lets_encrypt_resolver'
dynamic.yml
tls:
# traefik will terminate SSL and then communicate with self-signed certs internally.
certificates:
- certFile: /certs/cert.pem
keyFile: /certs/key.pem
http:
serversTransports:
myTransport:
serverName: "app"
rootCAs:
- /certs/rootCA.pem
routers:
app:
rule: Host(`app.mydomain.com`)
service: app
entryPoints:
- https
tls:
certResolver: lets_encrypt_resolver
services:
app:
loadBalancer:
serversTransport: myTransport
servers:
- url: 'https://app:8080'
The above configuration does work for valid subdomains. I can visit https://app.mydomain.com and I am served a valid https certificate along with my internal application serving the content via its own TLS cert.
The problem is, when I visit https://randomsubdomainthatdoesntexist.mydomain.com, I am served with a browser warning and traefik's default certificate is being served. Instead, I would like it to show me the standard 404.
My expectation was that having a wildcard certificate would enable this, which is why I switched from the HTTP challenge to the DNS challenge. Was I incorrect?
What am I missing?