I want to use PHP 7 with newer apps and PHP 5.6 with apps, that doesn't work with PHP 7. So I try to configure Nginx to enable different PHP versions for different pathes. But it doesn't work:
# should enable PHP5 for all PHP-scripts under /vexim/ path
location ^~ /vexim/.*\.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
And the default for anything else should be PHP 7:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
With this configuration PHP scripts under /vexim/ are not parsed at all. How to get this working with different pathes and PHP versions?
(Using Debian 8.3 Jessie, Nginx 1.8.1 (dotdeb), PHP 5.6, PHP 7 (dotdeb))
location ^~
is not a regex location, it is a prefix location that takes precedence over all regex locations.See this document for details.
What you probably want is:
Make sure that the
/vexim
location comes first as regex locations are ordered.