Laravel Use-case -> Caddyfile v1 to v2

1. My Caddy version (caddy version):

v2.0.0-beta.20

Hello, I am trying to migrage a caddy file v1 (under laradock) to a fresh caddy installation (v2) on Ubuntu 18.x

Here is the old Caddy File

https://sub.example.com,
*.sub.example.com {
    root /var/www/public
    fastcgi / php-fpm:9000 php {
        index index.php
        connect_timeout 1800s
        read_timeout 1800s
        send_timeout 1800s
    }

    rewrite {
        to {path} {path}/ /index.php?{query}
    }
    gzip
    browse
    log /var/log/caddy/access.log
    errors /var/log/caddy/error.log
    # Uncomment to enable TLS (HTTPS)
    # Change the first list to listen on port 443 when enabling TLS
    tls {
        max_certs 50
    }
}

And the fresh new one I started:

https://sub.example.com, *.sub.example.com {
        root * /var/www/myproject/current/public

        php_fastcgi 127.0.0.1:9000 php {
                index index.php
                connect_timeout 1800s
                read_timeout 1800s
                send_timeout 1800s
        }

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

I get on caddy reload the following error:

reload: adapting config using caddyfile: parsing caddyfile tokens for 'rewrite': Caddyfile:6 - Error during parsing: Wrong argument count or unexpected line ending after '{http.request.uri.path}/'

How can I use New Matchers in my use-case?

I am still a bit lost with the new caddy and documentation, any help would be appreciated :slight_smile:

Best regards,

Hi there, welcome โ€“

Have you looked at the upgrade guide? It will help ease the transition. I just updated it based on some things I see here.

Namely, the php_fastcgi directive is not the same as the fastcgi directive from v1. There is no php preset because PHP is already assumed by the directive name. :slight_smile:

So you probably need just php_fastcgi 127.0.0.1:9000 instead โ€“ and see if that works by itself. Remove the other config parameters, they are not in v2.

You can also eliminate the rewrite, as php_fastcgi does that for you: php_fastcgi (Caddyfile directive) โ€” Caddy Documentation

2 Likes

Your config will probably look like this:

https://sub.example.com, *.sub.example.com {
    root * /var/www/myproject/current/public

    php_fastcgi 127.0.0.1:9000

    encode gzip
    file_server
}
3 Likes

First thanks to both of you :slight_smile:

Indeed it is working much better now! I read the upgrade guide but some parts were not very clear to me.

it could be super-interesting to add a Caddyfile_v2 to examples/Caddyfile at master ยท caddyserver/examples ยท GitHub, what do you think?

Have a nice evening

@frenchvandal instead of deleting your post, what was your solution?

Sorry, none in Caddy actually! I did not want to make anyone lose time on this. After some hours spent on searching a solution, the problem was right under my nose.

I found out a symlink was broken because in the meantime I changed the root path inside the container (the images are not stored in the exposed root).

After fixing the symlink, the Caddy config you posted above works like a charm, no need to add any additional directives.

2 Likes

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