This is specific to nginx-unit the somewhat new mini web server from NGINX team, NOT the typical nginx + php-fpm combination.
I followed the nginx-unit symfony example down to the exact byte https://unit.nginx.org/howto/symfony/ and it works, except when I try hitting a PHP file that doesn't exist, example /foo/bar.php
, I get a Server 500 error with this message in logs:
PHP Fatal error: Unknown: Failed opening required '/app/public/foor/bar.php' (include_path='.:/usr/share/php') in Unknown on line 0
If I try accessing an aesthetic URL that doesn't exist such as /foo/bar
my app gets hit and the expected 404 logic is used. I'd like for non-existent PHP files to generate proper 404s but it isn't clear to me how to do this with nginx-unit.
My config is basically the exact same as the example, which I'll repeat here:
{
"listeners": {
"*:80": {
"pass": "routes/symfony"
}
},
"routes": {
"symfony": [
{
"match": {
"uri": [
"*.php",
"*.php/*"
]
},
"action": {
"pass": "applications/symfony/direct"
}
},
{
"action": {
"share": "/path/to/app/public/",
"fallback": {
"pass": "applications/symfony/index"
}
}
}
]
},
"applications": {
"symfony": {
"type": "php",
"user": "app_user",
"group": "app_group",
"targets": {
"direct": {
"root": "/path/to/app/public/"
},
"index": {
"root": "/path/to/app/public/",
"script": "index.php"
}
}
}
}
}
If I had to guess I would say that due to the match
part, *.php
is trying to do a direct PHP include operation internally (before my app script is ever hit). When errors say Unknown on Line 0
that usually means internal code that you cannot control except via configuration.