Update Nginx configuration for PHP handling#61
Conversation
Fixes #39 and allow NGINX to serve 404 pages again.
There was a problem hiding this comment.
Pull request overview
Updates the default NGINX virtual host to prevent unwanted absolute redirects (including port leakage) and to tighten/adjust PHP request handling so missing PHP scripts can correctly return 404.
Changes:
- Disable absolute redirects and suppress ports in redirect responses (
absolute_redirect off,port_in_redirect off). - Add a
try_filesguard in the PHP location to return 404 for non-existent PHP scripts. - Enable
fastcgi_intercept_errorsto allow NGINX to handle upstream error statuses (where configured).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| location ~ \.php$ { | ||
| try_files $uri =404; | ||
| fastcgi_split_path_info ^(.+\.php)(/.+)$; | ||
| fastcgi_pass unix:/home/container/tmp/php-fpm.sock; |
There was a problem hiding this comment.
The new try_files $uri =404; in the PHP location will 404 valid requests that include PATH_INFO (e.g. /index.php/some/path) because $uri includes the extra path segment and won’t exist on disk. If you want to prevent executing non-existent scripts while still supporting PATH_INFO-style routing, switch the existence check to the script name (e.g. $fastcgi_script_name) and ensure PATH_INFO is passed through consistently with fastcgi_split_path_info.
|
perhaps changing it to this would curb it's complaining. I need to do some testing. |
- Move fastcgi_split_path_info before try_files so $fastcgi_script_name is populated before the existence check runs - Use $fastcgi_script_name instead of $uri to correctly handle PATH_INFO requests (e.g. /index.php/some/path) without returning false 404s
|
Thanks for the contribution! I applied the changes manually with a small adjustment: using $fastcgi_script_name instead of $uri in the try_files check, as Copilot correctly pointed out that $uri would cause false 404s for PATH_INFO-style requests. I also moved fastcgi_split_path_info before try_files to ensure the variable is populated before the check runs. |
Fixes #39 and allows NGINX to serve 404 pages again.