Separate location for files served by php-fpm

Palvelin Postmaster postmaster at
Mon May 8 18:49:29 UTC 2023

Hi all!

I use php-fpm together with nginx.

My PHP app serves files which have hashed filenames and no filename extension from a specific subdirectory url, e.g /files/hash/31b4ba4a0dc6536201c25e92fe464f85

I would like to be able to set, for example, a separate ’expires’ value to these files with nginx (using a separate location block?). Is that achiavable?

server {
       listen 443 ssl http2;
       root /var/www/vhosts/;
       set $ngspage /index.php?ngspage=$uri$is_args&$args;

       # PHP file processing configuration
       location ~ [^/]\.php(/|$) {
               set $location_name php;
		fastcgi_pass php74;
               include fastcgi_params;
               fastcgi_index index.php;

               # Regex to split $uri to $fastcgi_script_name and $fastcgi_path
               fastcgi_split_path_info ^(.+?\.php)(/.*)$;

               # Bypass the fact that try_files resets $fastcgi_path_info
               # see:
               set $path_info $fastcgi_path_info;

               # Check that the PHP script exists before passing it
               try_files $ngspage $fastcgi_script_name =404;

More information about the nginx mailing list