docker-composetraefikcaddylaravel-octane

traefik + HTTPS + Caddy > Internal Server Error


I'm looking to upgrade our current laravel app, by using FrankenPHP to give it a performance boost. But I'm having issues when I try to deploy to our staging environment, so I'm trying to clone that setup as much as possible.

Our deployment setup uses nomad & traefik, so I'm trying to setup traefik locally to get a better understanding of the issue.

Anytime I load the application, I get a 500 error, I don't get any errors in any logs, so I'm walking blind on getting this to work.

If I run it as an http setup, it works no problem.

This the setup I'm using for everything.

composer.yml

networks:
  web:
    external: true

services:
  traefik:
    image: traefik:v2.4
    container_name: traefik
    command:
      - "--log.level=DEBUG"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
    networks:
      - web
    ports:
      - 80:80
      - 8080:8080
      - 443:443
    volumes:
      - ./docker/traefik/static.yml:/etc/traefik/traefik.yml:ro
      - ./docker/traefik/dynamic.yml:/etc/traefik/dynamic.yml:ro
      - ./ssl:/var/traefik2/tls:ro
      - /var/run/docker.sock:/var/run/docker.sock
  api:
    build:
      target: api-debug
    container_name: api
    image: api
    environment:
      - "SERVER_NAME=:80"
    env_file:
      - ./.env.docker-compose
    volumes:
      - ./app:/opt/api/app
      - ./bootstrap:/opt/api/bootstrap
      - ./public:/opt/api/public
      - ./routes:/opt/api/routes
      - ./storage:/opt/api/storage
      - ./resources:/opt/api/resources
      - ./.env.docker-compose:/opt/api/.env
    links:
      - database
      - cache
    networks:
      - web
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.myproject.rule=Host(`myproject.localhost`)"
      - "traefik.docker.network=web"
      - "traefik.http.services.myproject.loadbalancer.passhostheader=true"
      - "traefik.http.services.myproject.loadbalancer.server.scheme=https"
      - "traefik.http.routers.myproject.tls=true"
      - "traefik.http.routers.myproject.priority=100"
  cache:
    container_name: cache
    image: memcached:alpine
    networks:
      - web
    ports:
      - "11211:11211"
  database:
    image: mysql:8.4
    container_name: database
    platform: linux/x86_64
    environment:
      - MYSQL_DATABASE=app
      - MYSQL_ROOT_PASSWORD=secret
    ports:
      - 13306:3306
    networks:
      - web
    healthcheck:
      test: "/usr/bin/mysql --user=root --password=secret --execute \"SHOW DATABASES;\""
      interval: 3s
      timeout: 1s
      retries: 5

static.yml:

global:
  sendAnonymousUsage: false

api:
  dashboard: true
  insecure: true

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    watch: true
    exposedByDefault: false

  file:
    filename: /etc/traefik/dynamic.yml
    watch: true

log:
  level: INFO
  format: common

http:
  serversTransports:
    mytransport:
      certificates:
        - certFile: /var/traefik2/tls/local-cert.pem
          keyFile: /var/traefik2/tls/local-key.pem
      insecureSkipVerify: true

entryPoints:
  http:
    address: ":80"
    http:
      redirections:
        entryPoint:
          to: https
          scheme: https
  https:
    address: ":443"

dynamic.yml

http:
  routers:
    traefik:
      rule: "Host(`traefik.localhost`)"
      service: "api@internal"
      tls:
        domains:
          - main: "myproject.localhost"
            sans:
              - "*.myproject.localhost"

tls:
  certificates:
    - certFile: "/var/traefik2/tls/local-cert.pem"
      keyFile: "/var/traefik2/tls/local-key.pem"

Solution

  • You can’t use traefik.yml and command: at the same time for static config, decide for one (doc).

    Enable and check Traefik debug log (doc) and Traefik access log in JSON format (doc).

    JSON access log will tell you if the error status is coming from target service (OriginStatus) or only from Traefik (DownstreamStatus).