Caddy returns " domain is not served on this interface" with Docker and Traefik


(Joseph Levarato) #1

I’m using Hugo Framework to play around continuous deployment. I created an image containing Caddy server, Hugo and the test project I used for my tests, sent it to my server that runs Traefik and started the image.

Here is the Dockerfile:

FROM debian:latest

RUN apt-get update -y && apt-get install git curl -y
ADD https://github.com/gohugoio/hugo/releases/download/v0.42.2/hugo_0.42.2_Linux-64bit.deb /tmp/hugo.deb
RUN dpkg -i /tmp/hugo.deb && rm /tmp/hugo.deb
RUN curl https://getcaddy.com | bash -s personal
RUN chown root:root /usr/local/bin/caddy && chmod 755 /usr/local/bin/caddy
RUN mkdir /srv/app
WORKDIR /srv/app
COPY . ./
RUN git clone https://github.com/RealOrangeOne/hugo-theme-revealjs.git themes/hugo-theme-revealjs
RUN hugo
EXPOSE 2015
CMD ["caddy"]

And here is the “docker-compose.yml” that runs my project on my server:

my_project:
  image: some_registry/my_project
  ports:
    - "2015:2015"
  labels:
    - "traefik.frontend.rule=Host:subdomain.domain.me"

I almost forgot, here is my Caddyfile:

localhost:2015
root /srv/app/public

The image runs without problem, but when reaching subdomain.domain.me, I get the following message:

404 Site subdomain.domain.me is not served on this interface

However, running curl http://localhost:2015 prints my project’s HTML on my server.

So… I think the problem comes from Caddy, since I have no problem when using Apache, and about 5 other of my projects use Traefik without problem.

My question is: how should I edit my Caddyfile so that I don’t have this problem?

Thank you in advance


(Matthew Fay) #2

By way of explaining what’s happening here, the first thing that should be noted is that Caddy uses the site label to match the requested Host when determining what configuration to use.

When you use the site label localhost, you’re telling Caddy to only serve that site when a client requests localhost - not subdomain.domain.me, not example.com, not the IP address.

When Traefik forwards a frontend request, it will include the requested Host. Since clients are obviously requesting the domain name, not localhost, the site label doesn’t match.

To fix it, you need to change your site label.

You could generalize it (use :2015 instead of localhost:2015), which configures Caddy to use the site definition for any hostname requested on the port. This lets you curl http://localhost:2015 AND lets Traefik get the site when requesting subdomain.domain.me. This is much less useful if your Caddy instance serves more than one website.

Alternately, you can adjust it to suit the Host on the incoming requests. Since we know this will always be subdomain.domain.me because of the Traefik frontend rule, you’ll want to use http://subdomain.domain.me:2015.