caddy icon indicating copy to clipboard operation
caddy copied to clipboard

static directory index fails with an explicit try_files configuration

Open colinlli opened this issue 3 weeks ago • 2 comments

Issue Details

I encountered the same issue on Caddy v2.11.9, running in Docker.

My setup uses both php_fastcgi and file_server. The problem occurs when accessing a directory that contains an index.html file but does not have an index.php file.

Environment

  • Caddy version: v2.11.9
  • Deployment: Docker
  • PHP backend: PHP-FPM (separate container)

Caddyfile

Here is a simplified version of my configuration:

example.test:80 {
    root * /srv/site

    php_fastcgi php-fpm:9000 {
        try_files {path} {path}/index.php
    }

    file_server
}

Directory structure

/srv/site/
└── xxxxxx/
    └── index.html

There is an index.html inside the wxwork directory, but no index.php in that directory.

Steps to reproduce

  1. Start Caddy v2.11.9 with the configuration above.
  2. Request /xxxxxx/.
  3. Request /xxxxxx/index.html directly.

Actual behavior

  • GET /xxxxxx/ returns 404 with the response body File not found.
  • GET /xxxxxx/index.html works correctly and serves the HTML file.

Expected behavior

When requesting /xxxxxx/, Caddy should detect the existing index.html and serve it through file_server, rather than attempting to execute a non-existent PHP index file through PHP-FPM.

Direct requests to existing PHP files should continue to be handled by php_fastcgi as usual.

Additional notes

The issue appeared after upgrading Caddy. The same configuration worked correctly with the previous version.

The index.html file is present and accessible from the Caddy container, as demonstrated by the fact that requesting /xxxxxx/index.html directly works.

One detail worth investigating is that this configuration explicitly specifies:

try_files {path} {path}/index.php

Could you confirm whether the fix in #8372 also addresses this explicit try_files configuration?

Thank you!

Assistance Disclosure

AI used

If AI was used, describe the extent to which it was used.

ChatGPT translated from my native language

colinlli avatar Nov 11 '26 10:11 colinlli

I tested this with the exact config from the report, using a stub FastCGI upstream that echoes SCRIPT_FILENAME, a directory xxxxxx/ containing only index.html, and a second directory phpdir/ containing index.php. Same test run against two revisions:

v2.11.9 (tag 0d98caea) — reproduces the report

  • GET /xxxxxx/ is rewritten to /xxxxxx/index.php and handed to FastCGI, even though that file does not exist. With a real PHP-FPM that is the 404 File not found. from the report.
  • GET /missing is also rewritten to /missing/index.php.

master (f458aa00) — fixed

  • GET /xxxxxx/ returns 200 with the index.html content, served by file_server.
  • GET /phpdir/ still rewrites to the existing index.php and is proxied.
  • Direct requests to existing .php files are still proxied.
  • GET /missing returns 404 from file_server, nothing is passed to FastCGI.

The difference is #8372. It removed the try_policy that parsePHPFastCGI used to infer for php_fastcgi, in all cases and not only for the default try_files, so an explicit try_files {path} {path}/index.php now gets first_exist behaviour instead of first_exist_fallback. (The PR note about explicitly configured first_exist_fallback keeping its semantics still holds where a policy can actually be set by hand, i.e. on a file matcher.) v2.11.9 was released 2026-11-05, before #8372 merged, so the fix should ship in the next release.

Assistance Disclosure

AI was used to help run the A/B test described above and to draft this comment. The test results were verified against both revisions before posting.

0xABCD01 avatar Nov 11 '26 11:11 0xABCD01

can i work on this

aynaash avatar Nov 11 '26 17:11 aynaash