[solved] Is there a matched path as placeholder in Caddy 2?


I’m trying to execute Perl scripts via CGI and Caddy 2 for certain URLs.

For Caddy 1, the CGI plugin at GitHub - jung-kurt/caddy-cgi: Common Gateway Interface plugin for the Caddy HTTP server used a {match} placeholder that captured what the matcher matched, e.g. when specifying /*.pl, {match} contained /script1.pl, depending on the URL.

I am trying to replicate this via Caddy 2 and the CGI plugin GitHub - aksdb/caddy-cgi: Common Gateway Interface plugin for the Caddy HTTP server, however, I am unable to find an equivalent. {path} would work, but unfortunately the script can specify extra arguments separated by a slash after the script name, which I am unable to trim. To illustrate, I have URLS like:

https://example.com/script1.pl/1234/5678, or https://example.com/script2.pl?query=value

Supposing that the *.pl matcher matches script1.pl, the old CGI directive could look like this:

cgi *.pl /usr/local/cgi-bin{match}

which would execute /usr/local/cgi-bin/script1.pl

Thanks for any help in advance.


You can use the path_regexp matcher, which lets you use capture groups, which are then available as placeholders.

Btw, *.pl will not match a request path /script1.pl/1234/5678 because /1234/5678 is still part of the path. You would need to do something like *.pl* but that doesn’t really make sense because it would often match too much.

The way it works for PHP apps is explained in the php_fastcgi expanded form, see the part about split_path. This should explain what you’d need to do in your case:

1 Like

Thank you very much, especially for the super quick reply and for catching my path mistake at the same time. I’m not even mentioning how helpful the provided links are, as the documentation can be slightly overwhelming after a while :relaxed:


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