Hi, I had some trouble enabling cors among other stuff so Iâve decided to make the jump to V2. I have been doing changes to my V1 CaddyFile but I just canât get the rewrites done.
4. Error messages and/or full log output:
caddy run --config /etc/caddy/Caddyfile --adapter caddyfile
2020/09/12 08:54:07.393 INFO using provided configuration {âconfig_fileâ: â/etc/caddy/Caddyfileâ, âconfig_adapterâ: âcaddyfileâ}
run: adapting config using caddyfile: parsing caddyfile tokens for ârewriteâ: /etc/caddy/Caddyfile:10 - Error during parsing: Wrong argument count or unexpected line ending after ârewriteâ
5. What I already tried:
I readed all the documentation specially the V2 made for migration. I couldnât see any info about ext and I tried removing r & to. but itâs something I just canât get it done. While I honestly donât want my files completely done, I would appreciate some tips on this.
Please use caddy fmt to clean up your config, itâll fix all the indentation and make your config much easier to read!
The rewrite directive in v2 has different syntax. It doesnât take subdirectives anymore for request matching, instead it uses the generalized request matching system introduced in v2.
For example, this one:
rewrite {
r /(.git|admin|pihole|logs|backups|tests)/.*$
to /denyaccess
}
Also, have you gone through the upgrade guide? It should cover a lot of the other things youâve missed, like:
how to use the php_fastcgi directive (no php preset anymore at the end of the line, new syntax for unix sockets)
the change to root (you need * as the first param as the matcher if using a absolute path, i.e. path starting with /, because things starting with / can be path matchers)
you should use the root directive rather than the root subdirective to file_server, so that root is set for all directives rather than just file_servers (because php_fastcgi needs to know where the files are stored as well)
the php_fastcgi directive has built-in try_files behaviour so you should no longer need the to /index.php?{1} rewrites
I wanted to add some error pages but I heard theyâre being reworked for 2.1. so Iâll wait a little.
I definitely need to start studying again all of this. I forgot most of it!
A few more things Iâm noticing - you need to add unix/ as a prefix to the socket path for your php_fastcgi directive for Caddy to understand that itâs a unix socket. Like this:
php_fastcgi unix//var/run/lighttpd/php.socket-0
Also, you can remove both subdirectives to file_server because you already set root, and php_fastcgi takes care of making index.php an index file already.
And finally, you can omit the /* on your header directive, because omitting a matcher is the same as âmatch all requestsâ (as long as the first argument doesnât start with / or @)