Skip to content

fix(webserver-config): scope nginx php handler per app for correct SCRIPT_FILENAME#18

Draft
TDannhauer wants to merge 1 commit into
FRAMEWORK_6_0from
fix/nginx-subpath-script-filename
Draft

fix(webserver-config): scope nginx php handler per app for correct SCRIPT_FILENAME#18
TDannhauer wants to merge 1 commit into
FRAMEWORK_6_0from
fix/nginx-subpath-script-filename

Conversation

@TDannhauer

Copy link
Copy Markdown
Contributor

Summary

Motivation

#17 emitted a single server-scope location ~ \.php$ using
SCRIPT_FILENAME $document_root$fastcgi_script_name. For an aliased
subpath app (e.g. /imp/) $document_root points at the server root,
not the app fileroot, so php-fpm receives a wrong path and cannot run the
front controller. With no root-anchored app there is no root directive
at all, leaving every subpath app unservable. Apache was unaffected; CI
only served the Apache flavor, so this went uncaught.

Changes

  • NginxEmitter: wrap each app in a ^~ prefix location; nest the PHP
    handler per app with $document_root$fastcgi_script_name (root-anchored)
    or $request_filename (subpath, honours the alias). Forbid blocks and
    the try_files fallback move inside the same location; the redundant
    server-scope handler is removed. Banner documents the PATH_INFO caveat.
  • Tests: NginxEmitterTest, AppMapBuilderTest, GenerationContextTest,
    WebserverConfigOptionsTest.

Test plan

  • vendor/bin/phpunit full suite green (195 tests)
  • New tests assert $request_filename for subpath, $document_root
    for root-anchored, nested forbid blocks, and no server-scope handler
  • Manual: generate an nginx config for a subpath app and confirm
    php-fpm serves the front controller

…RIPT_FILENAME

The nginx flavor emitted a single server-scope `location ~ \.php$` block
using `SCRIPT_FILENAME $document_root$fastcgi_script_name`. That only
resolves for a root-anchored app served from the server-level `root`;
for an aliased subpath app the expression points at the server root
rather than the app fileroot, so php-fpm cannot find the script. When no
app is root-anchored there is no `root` at all and every subpath app is
unservable without manual edits.

Wrap each app in a `^~` prefix location and nest its php handler so
SCRIPT_FILENAME reflects the app's anchoring: $document_root$fastcgi_script_name
for root-anchored apps, $request_filename (which honours the alias) for
subpath apps. Forbid blocks and the front-controller try_files fallback
move inside the same location, preserving dispatch order.

Add unit tests for the previously untested WebserverConfig services:
NginxEmitter, AppMapBuilder, GenerationContext and WebserverConfigOptions.
@TDannhauer
TDannhauer requested a review from ralflang July 8, 2026 19:03
@TDannhauer

Copy link
Copy Markdown
Contributor Author

@ralflang basically my review

@ralflang

ralflang commented Jul 8, 2026

Copy link
Copy Markdown
Member

I'm sceptical of this analysis. I think I'd better park this one until we actually do have the nginx CI pipeline.

@ralflang
ralflang marked this pull request as draft July 8, 2026 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants