Caddyfile 2 for Laravel site

1. Caddy version (caddy version): 2

2. How I run Caddy:

I run Caddy in Docker container

a. System environment:

Docker with 3 containers: php-fpm, caddy, mysql

d. My complete Caddyfile or JSON config:

educraft.test:80, 0.0.0.0:80 {
    root /app/public

    fastcgi / educraft_php:9000 php

    rewrite {
        to {path} {path}/ /index.php?{query}
    }

    errors stdout
    log stdout

    timeouts 3m
}

3. The problem I’m having:

I have Laravel 7 app.
I need to convert Caddyfile version 1 to version 2. I was convert all except url rewriting. It doesn’t working.

This is my Caddyfile 2:

educraft.test:80 {
    root * /app/public

    rewrite * /index.php?{query}
    php_fastcgi / educraft_php:9000

    file_server
    #encode gzip
    log
}

Please help me convert v1 to v2 right.

I think the part that is tripping you up is this:

  • Where you matched requests by path prefix in Caddy 1, path matching is now exact by default in Caddy 2. If you want to match a prefix like /foo/ , you’ll need /foo/* in Caddy 2.

This means that the / in your php_fastcgi directive will only match requests to / and nothing else. Just remove the / and it will work. The rewrite is also not necessary because that’s now built into the php_fastcgi logic, which does a try_files rewrite similarly to what you had in your v1 config.

educraft.test:80 {
    root * /app/public

    log
    encode gzip

    php_fastcgi educraft_php:9000

    file_server
}

Thank you, it’s working now - you save me tons of time!

1 Like

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