My understanding is that the first example, you’re attempting to serve /var/www/backend/public/api/v3/index.php and in the second example you’re serving /var/www/backend/public/index.php (both as absolute file paths within the PHP container).
My next point to troubleshoot would be to determine whether both exist and have the same file ownership and permissions inside the container, since the latter is proven to work.
That looks to be the case, as deducible from the php-fpm logs.
/var/www/backend/public/api/v3/index.php is not valid, it is indeed supposed to be /var/www/backend/public/index.php. Below are a couple more configurations and accompanying logs that i have tried.
Results in a Caddy 404, never reaches fpm container.
This is expected behaviour. You rewrite to fall back on /index.php, but your fastcgi is configured only to proxy paths beginning with /api/v3/, so the request is handled by the default Caddy static fileserver and 404’d (no index.php in your web root, I expect).
Unsure on your NotFoundHttpException, but Caddy is acting exactly as you’ve configured here. Your host is example.com/api/v3 and a request to /example on this host results a rewrite to /index.php which is appended to the host to result in example.com/api/v3/index.php. The URI is then passed on to FastCGI, resulting in a request for /api/v3/index.php, correlating with the root subdirective to the absolute file path /var/www/backend/public/api/v3/index.php on disk within the PHP container.
Thank you for the detailed response. It is very much appreciated.
The application residing on the fpm container is expecting to see the route /api/v3/example. By using the below Caddy config, and removing the /api/v3 route prefix expectation from the application…
I guess the question is how would i go about configuring Caddy to also pass through the /api/v3 prefix? Ideally i would have the single example.com label as i have quite a bit going on in that definition, e.g. the landing page, proxying of subdirectories to other services, etc. - or is doing the above the only solution?
which is remarkably similar to what you put in the initial paragraph.
Both versions of this configuration send the request /api/v3/index.php to FastCGI with a root of /var/www/backend/public, so theoretically, neither should work unless /var/www/backend/public/api/v3/index.php exists within the PHP container.
Well, I’m stumped. Unless there’s something else changing between tests, I’m not sure how PHP can be giving two different results for the same file here…
I think what you want is to rewrite to this: index.php?q=/api/v3. I haven’t tested, but hopefully that pushes you in the right direction. Lumen/Laravel check the q url param for the path.
I could be way off here, but having a quick look at the fastcgi code, it looks like the SCRIPT_FILENAME cgi variable is possibly being passed as /var/www/backend/public/api/v3/index.php in the below configuration
I find myself wondering whether or not, for site label example.com/foo/bar and a request to /foo/bar/test, the r.URL.Path is actually /foo/bar/test or just /test, which might explain the discrepancy?