I have no idea how to convert this nginx fastcgi setup to caddy

I’m trying to convert the following Nginx config section to Caddy and I have no idea where to start really. I’m reading the rewrite section and fastcgi. It was very easy to get the PHP FPM working.

  try_files $uri $uri/ @rewrite;
  location @rewrite {
    rewrite ^/(.*)$ /index.php?url=$1 last;

  location ~ \.php {
    fastcgi_index  /index.php;

    include fastcgi_params;
    fastcgi_split_path_info       ^(.+\.php)(/.+)$;
    fastcgi_param PATH_INFO       $fastcgi_path_info;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

Hi @dschissler, welcome to the Caddy community.

There are really only two main parts to the nginx config you’ve provided;

  1. Rewrite from ^/(.*)$ to /index.php?url=$1, and;
  2. FastCGI proxy php scripts to

These two are super easy to replicate in a Caddyfile - the only somewhat complex part is the rewrite. You can give the rewrite directive the exact same regex string that nginx takes. However, instead of $1, $2 etc., Caddy’s regex substitutions take the form {1}, {2}, etc., so you need to modify the destination appropriately. Put it all together and you get:

rewrite {
  regexp ^/(.*)$
  to /index.php?url={1}

The fastcgi part is incredibly simple by comparison:

fastcgi / php

That’s all there is to it!


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