502 bad gateway with caddy and php_fastcgi

Hello,

Still trying to understand how to configure my dev stack with Caddy.

I’m now at the step “multiple php versions”.

My configuration is:

{
  networking.firewall.allowedTCPPorts = [ 80 443 ];
  services.caddy = {
    enable = true;
    virtualHosts = {

      "php80.localhost" = {
        extraConfig =
          ''
            root * /var/www
            file_server
            php_fastcgi unix/${config.services.phpfpm.pools.php80.socket}
          '';
      };

      "php81.localhost" = {
        extraConfig =
          ''
            root * /var/www
            file_server
            php_fastcgi unix/${config.services.phpfpm.pools.php81.socket}
          '';
      };

    };
  };

  # multiple php versions
  services.phpfpm.pools = {
    "php80" = {
      user = "caddy";
      group = "caddy";
      phpPackage = pkgs.php80;
      settings = {
          # ...
      };

    };
    "php81" = {
      user = "caddy";
      group = "caddy";
      phpPackage = pkgs.php81;
      settings = {
          # ...
      };

    };
  };
}

My problem : when I try to load a php file, I have a 502 bad gateway error.

Got it (was strugling with it since two days :sweat_smile: )

I had to add
"listen.owner" = "caddy";
to the settings part of each pool.

1 Like

https://sourcegraph.com/search?q=context%3Aglobal+lang%3Anix+"listen.owner"+%3D+"caddy"%3B&patternType=standard&sm=1&groupBy=repo

interesting. these two users got it before you.

Does caddy have a nixos test? but i’m not sure if it would actually help in this case.

I want configuration ‘caveats’ like this to be more discoverable, but i’m not sure how that would work, or if it can be done.

Actually I found the information on the wiki with the example for nginx configuration Phpfpm - NixOS Wiki

1 Like