Fix asset/URL port mismatch when proxy.port differs from nginx/caddy's own listen port
Asatru's own url()/asset() helpers build absolute URLs from $_SERVER['SERVER_PORT'] rather than APP_URL, and nginx/caddy populate that from the port they're actually listening on -- not an externally forwarded one (e.g. the QEMU test VM's hostfwd to 8080). That silently dropped the port from every generated asset/redirect URL, breaking all static assets when accessed through a forwarded port. Override SERVER_PORT at the fastcgi layer to cfg.port when set, for both backends. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -439,6 +439,14 @@ in {
|
||||
include ${config.services.nginx.package}/conf/fastcgi_params;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
${lib.optionalString (cfg.port != null) ''
|
||||
# Asatru's own url()/asset() helpers (vendor/danielbrendel/asatru-php-framework/src/helper.php)
|
||||
# build every absolute URL straight from $_SERVER['SERVER_PORT'], never from APP_URL. That
|
||||
# default fastcgi_params' $server_port is the port nginx itself listens on -- e.g. the QEMU
|
||||
# test VM's unforwarded guest port 80 -- not the externally-reachable/forwarded one (8080),
|
||||
# so every asset/redirect URL silently drops the real port. Override it to match cfg.port.
|
||||
fastcgi_param SERVER_PORT "${toString cfg.port}";
|
||||
''}
|
||||
'';
|
||||
|
||||
# Don't let anyone fetch the rendered .env or app internals.
|
||||
@@ -471,7 +479,15 @@ in {
|
||||
|
||||
# php_fastcgi already covers the Asatru front-controller rewrite
|
||||
# (try real file, then index.php) and static file serving.
|
||||
php_fastcgi unix/${config.services.phpfpm.pools.hortusfox.socket}
|
||||
php_fastcgi unix/${config.services.phpfpm.pools.hortusfox.socket} {
|
||||
${lib.optionalString (cfg.port != null) ''
|
||||
# See the matching nginx fastcgi_param SERVER_PORT override above:
|
||||
# Asatru's url()/asset() helpers build absolute URLs from
|
||||
# $_SERVER['SERVER_PORT'] alone, which Caddy otherwise sets to the
|
||||
# port it's actually listening on rather than an external/forwarded one.
|
||||
env SERVER_PORT ${toString cfg.port}
|
||||
''}
|
||||
}
|
||||
file_server
|
||||
'';
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user