Wit the following setup I don't know how to make nginx pass the CGI request to the index script in the appropriate version subdirectory. It instead serves the index as a download.
PHP-FPM is a linked docker container.
server {
listen 80;
root /var/www/html/public;
server_name _;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
index index.html index.htm index.debian-default.html index.php;
location ~ /(?<version>v.*)/ {
try_files $uri $uri/ /$version/index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
If I nest the proxy location block and change script filename into:
fastcgi_param SCRIPT_FILENAME $document_root/$version/$fastcgi_script_name;
when querying http://localhost/v1/
I get
nginx_1 | 2021/05/19 07:19:28 [error] 29#29: *3 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.26.0.1, server: _, request: "GET /v1/ HTTP/1.1", upstream: "fastcgi://172.26.0.2:9000", host: "localhost:9081"
nginx_1 | 172.26.0.1 - - [19/May/2021:07:19:28 +0000] "GET /v1/ HTTP/1.1" 404 27 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0"
php-fpm_1 | 172.26.0.3 - 19/May/2021:07:19:28 +0000 "GET /v1/index.php" 404
in the nginx
and php-fpm
logs respectively.
php-fpm
address?