I am currently trying to understand the functionality of Caddy and FastCGI. I have a setup that was working perfectly fine with NGINX and where I want to switch to Caddy to use the built-in SSL functionality. I am setting up 2 services in my Docker Compose configuration:
- A PHP service (based on php:8.2-fpm-alpine) containing my PHP Symfony application
- A Caddy service that is supposed to pass requests to my PHP container
First of all, the following was my NGINX configuration file:
server {
listen 80;
index index.php index.html;
root /srv/app/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_hide_header X-Powered-By;
}
}
With this setup, the NGINX server passed requests to my PHP service named "php" without mounting or copying my source code into the NGINX image. I have to admit, I do not quite understand why I need the "root" directive when it is just an empty folder in my NGINX container.
Now with Caddy, I switched to the following configuration:
localhost {
root * /srv/app/public
php_fastcgi ${PHP_SERVICE_NAME}:9000
file_server
}
This Caddy configuration is working as well, but only when mounting my source code into the server container. Once removing the bind mount, all I get is a "404 Not Found".
So I hope someone can help me with my understanding of FastCGI and Caddy and tell me what I need to change in my configuration so that access to the source code from within the Caddy container is not needed.