I'm writing a web application using Slim 3, and am having difficulty getting nginx to play nicely with one of my routes.
My application allows users to upload files and view them, simple enough. This generates URLs like /viewfile/{user_id}/{filename}
. When the filename ends in .php
, I would expect nginx's try_files
to detect if it exists before attempting to pass it on to php-fpm. However, I suppose the php
location block is still trying to serve it as a valid PHP file, as I keep getting php-fpm's No input file specified.
error when attempting to view an uploaded php file.
Is there any way to get nginx to not attempt to serve all PHP file using php-fpm and instead pass it on to index.php
like the rest of the nonexistent URLs do, but still maintain the ability for only existing PHP files to be served?
Here is my config, trimmed down to the relevant parts, if it's necessary:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
root /var/www/html/public;
index index.php index.html index.htm;
server_name {redacted};
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/run/php-fpm/php7.0-fpm.sock;
include fastcgi_params;
}
}