I have a site using the standard nginx approach for directing traffic via /index.php regardless of url:
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
include fastcgi_params;
}
But I want to use a different php-fpm pool for a certain URL (but still going via /index.php). I could, I presume, use an "if" clause within the .php$ location block to use a different fastcgi_pass depending on the URL, but "if" is discouraged so is there another way?
You can use the
map
feature for this. For example, define themap
inhttp
context as follows:And then at the
location
:I haven't tested this approach myself, so you might need to tweak the
$pool
variable contents.