Separate location for files served by php-fpm

Palvelin Postmaster postmaster at palvelin.fi
Mon May 15 22:46:14 UTC 2023


Can anyone help me with this?


> On 8. May 2023, at 8.49, Palvelin Postmaster via nginx <nginx at nginx.org> wrote:
> 
> 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;
>       server_name my.site.com;
>       root /var/www/vhosts/my.site.com/site/;
>       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: http://trac.nginx.org/nginx/ticket/321
>               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