location ^~ /{{HOST}}/ { alias "{{PATH}}"; index index.php index.html; autoindex on; # Use a named location for reliable alias fallback try_files $uri $uri/ @{{HOST}}; # PHP handling nested INSIDE the alias location to maintain context location ~ \.php$ { fastcgi_pass 127.0.0.1:{{PHP_PORT}}; fastcgi_index index.php; include "{{CONF_DIR}}/fastcgi_params"; # Normal files matched correctly by URI don't suffer the try_files bug fastcgi_param SCRIPT_FILENAME $request_filename; } } # The named location handles requests that don't match physical files location @{{HOST}} { # Directly execute PHP without URI mutation to preserve framework routing paths fastcgi_pass 127.0.0.1:{{PHP_PORT}}; include "{{CONF_DIR}}/fastcgi_params"; # Hardcode the essential execution parameters fastcgi_param SCRIPT_FILENAME "{{PATH}}index.php"; fastcgi_param SCRIPT_NAME "/{{HOST}}/index.php"; fastcgi_param DOCUMENT_ROOT "{{PATH}}"; }