0

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?

Peter Howe
  • 203
  • 2
  • 9

1 Answers1

1

You can use the map feature for this. For example, define the map in http context as follows:

map $request_uri $pool {
    "/path/to/special" unix:/run/php/special.sock;
    default unix:/run/php/php7.0-fpm.sock;
}

And then at the location:

location \.php$ {
    fastcgi_pass $pool;
}

I haven't tested this approach myself, so you might need to tweak the $pool variable contents.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63