Getting Grav CMS to work + default site?

1. Caddy version (caddy version):

v2.1.1 h1:X9k1+ehZPYYrSqBvf/ocUgdLSRIuiNiMo7CvyGUQKeA=

2. How I run Caddy:

I run caddy on isaacs.site and I’m trying to run the Grav CMS. If you’re trying to access this domain right now I’ve commented out the entire isaacs.site block so the server will start back up again in the meantime. Same with :80

a. System environment:

CentOS 8, PHP 7.3 FPM, no SELinux

d. My complete Caddyfile or JSON config:

{
	experimental_http3
}
sync.isaacs.site {
	reverse_proxy localhost:8384
	encode zstd gzip
}
mail.isaacs.site, autodiscover.isaacs.site, autoconfig.isaacs.site {
	reverse_proxy localhost:8080
	encode zstd gzip
}
isaacs.site {
	root * /var/www/isaacs.site
	php_fastcgi / unix//run/php-fpm/www.sock
	file_server
	
	respond /403 "403 Forbidden" 403
    
    # rewrite rules I'm having issues with, attempted to adapt from https://github.com/getgrav/grav/blob/develop/webserver-configs/Caddyfile but I have no idea what I'm doing
    rewrite ^/(\.git|cache|bin|logs|backups|tests)/.*$ /403
    # deny running scripts inside core system folders
    rewrite /(system|vendor)/.*\.(txt|xml|md|html|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ /403
    
    # deny running scripts inside user folder
    rewrite /user/.*\.(txt|md|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ /403
    
    # deny access to specific files in the root folder
    rewrite /(LICENSE\.txt|composer\.lock|composer\.json|nginx\.conf|web\.config|htaccess\.txt|\.htaccess) /403
    
    # global rewrite should come last.
    rewrite {path} {path}/
    rewrite * /index.php?_url={uri}&{query}
}

# trying to be the fallback server, instead redirects all websites on port 80
#:80 {
#        respond "Hi there. You might want to be at https://isaacs.site."
#}

3. The problem I’m having:

I’m trying to run the Grav CMS. It seems like they haven’t updated the Caddyfile in a while (still v1) on the repo and none of the rewrite rules work. I’ve tried adapting them to the new format but I don’t know if we can even still use regex or if there’s a better way to do these rules that I’m missing… nothing I’ve tried seems to help. This is the example Grav config: grav/Caddyfile at develop · getgrav/grav · GitHub
In addition to this I’m also having problems with the :80 bracket below, I just want a default listener online for anything else that’s pointed to it but not configured with a simple message, self signed SSL is fine too.

4. Error messages and/or full log output:

validate: adapting config using caddyfile: parsing caddyfile tokens for 'rewrite': /etc/caddy/Caddyfile:20 - Error during parsing: Wrong argument count or unexpected line ending after '/403'

5. What I already tried:

I tried escaping / in the rules, escaping ., adding ^ to the beginning, adding $ to the end, not sure what else I should be doing to get these to work…
For the :80 rule I’m having issues with I’ve tried changing it to localhost and *:80 but it continues to take over every host’s port 80 instead of just the undefined ones. Again I’m fine with SSL as well but I’d at least like non-SSL to work and display a page on undefined domains since that’s still the default request browsers do on a new URL.

Please read these pages of the docs:

Specifically read the section about request matching. You can’t have inline regexp matchers, you must used a named matcher. Also matchers are exact-match in v2 so your matcher for php_fastcgi will only match requests to the root of your site.

Thanks for the pointers, I’ll see what I can figure out. :slight_smile:

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