Yet another Caddyfile help request (Directus CMS)

Hi guys,

I would like a hand and some more savvy minds to verify that I’ve got the correct setup for my Caddyfile.
I want to work with the headless CMS Directus using Caddy.

Based on the nginx conf that comes supplied with Directus I have put together the following:

    http://localhost
    fastcgi / 127.0.0.1:9000 php
    rewrite /api {
        to {path} {path}/ /api/api.php?run_api_router=1
    }
    rewrite {
        to {path} {path}/ /index.php?{query}
    }

It kinda works but obviously I’ve skipped a whole bunch of directives. I would like to make it more complete obviously.
It is based off of the following nginx conf lines:

    location /api {
        if (!-e $request_filename) {
            rewrite ^/1/extensions/([^/]+) /api/api.php?run_extension=$1 last;
        }
        rewrite ^ /api/api.php?run_api_router=1 last;
    }

    location / {
        try_files $uri $uri/ /index.php$args;
    }

For complete clarity, there is also an htaccess file.

I appreciate any help. If we arrive at a complete solution, I’ll be adding this to the caddyserver/examples repo.

1 Like

No one been able to help this out yet? I hate having to use my Directus with apache…it feels dirty…!

1 Like

I think the only part you’re missing is this one:

if (!-e $request_filename) {
    rewrite ^/1/extensions/([^/]+) /api/api.php?run_extension=$1
}

First up, it’s checking for the existence of a file, which I don’t think is something Caddy can do. In the example, if it doesn’t find an existing file, it does a complex rewrite, but it’s just standard regex. You could achieve similar, see rewrite. The following is untested:

rewrite /api {
    regexp ^/1/extensions/([^/]+)
    to /api/api.php?run_extension={1}
}
2 Likes

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