502 with php_fastcgi

I’m using Caddy and php-fpm with Docker compose. The issue is the request is not even being sent to the php-fpm container.

Caddyfile

{
    debug
}

app.domain {
    root * /srv/laravel/public
    encode zstd gzip
    php_fastcgi wep-app:9000 {
        root /var/www/html/public
    }
    file_server
    log {
        output file /var/log/caddy/app.log
    }
}

docker-compolse.yaml

services:
  web-app:
    image: ghcr.io/my-image/web-app
    restart: unless-stopped
    mem_limit: 8G
    volumes:
      - laravel_public_volume:/var/www/html/public

  caddy:
    build:
      dockerfile: ./dockerfiles/caddy/Dockerfile
    restart: unless-stopped
    env_file:
      - './envs/caddy/production.env'
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ./configs/caddy/Caddyfile-production:/etc/caddy/Caddyfile
      - ./caddy/data:/data
      - laravel_public_volume:/srv/laravel/public

volumes:
  laravel_public_volume:

Caddy error log

{
    "level": "debug",
    "ts": 1708679860.2886791,
    "logger": "http.handlers.reverse_proxy",
    "msg": "upstream roundtrip",
    "upstream": "wep-app:9000",
    "duration": 0.002582091,
    "request": {
        "remote_ip": "xx",
        "remote_port": "64560",
        "client_ip": "xx",
        "proto": "HTTP/2.0",
        "method": "GET",
        "host": "app.domain",
        "uri": "/index.php",
        "tls": {
            "resumed": false,
            "version": 772,
            "cipher_suite": 4865,
            "proto": "h2",
            "server_name": "app.domain"
        }
    },
    "error": "dialing backend: dial tcp: lookup wep-app on 127.0.0.11:53: server misbehaving"
}

Repeating what I wrote on Discord…

This looks wrong to me, you should be mounting your entire Laravel app, not just public, because it’s not just index.php that runs, it’s also files that are in directories parent to that.

But yes, your root in your Caddyfile should have /public.

Oh I just noticed it the problem :joy:

wep-app != web-app, (p != b)

Classic typo.

Oh, man! Thanks a lot, it was that typo thing!! wep not web :see_no_evil:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.