My request looks like this
domain.com/lib/browser/detect.js
Now internally I would like to serve /lib/browser/detect.php
My Nginx conf looks like this
location = /lib/browser/detect.js {
try_files non-existent /lib/browser/detect.php;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+?\.php)(/.*);
fastcgi_read_timeout 900s;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Nginx forces my browser to download this file.
Try using the
rewrite
directive instead oftry_files
as that is meant to server static files only.Something like this might do it:
The
rewrite
in this case can probably match on anything since it's already inside an exact match location block. You could also make the match in therewrite
directive and take it out of the location block and into the server block like I've done in my test here:This is otherwise default config from nginx and php-fpm packages on alpine linux. Contents of fastcgi.conf file are:
The only way so far I found is this