I have done a load of searching for an answer for this and I cannot find a suitable answer.
Basically, I have a site built in SilverStripe running on NGINX. It all works pretty well, but I want any files/images uploaded via the admin (to the assets folder) to be resolved via index.php in the site root (so we can check permissions of the files set in the admin before returning them to the user).
I have a pretty simple nginx config (for my local docker instance):
server {
include mime.types;
default_type application/octet-stream;
client_max_body_size 0;
listen 80;
root /var/www/html;
location / {
try_files $uri /index.php?$query_string;
}
location ^~ /assets/ {
try_files $uri /index.php?$query_string;
}
location /index.php {
fastcgi_buffer_size 32k;
fastcgi_busy_buffers_size 64k;
fastcgi_buffers 4 32k;
fastcgi_keep_conn on;
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
The issue is the lines:
location ^~ /assets/ {
try_files $uri /index.php?$query_string;
}
Unfortunately try_files
checks for a file's existence before handing the request over to php. Is there a way to stop this and hand all requests from the assets directory directly to PHP?