大网数据广告活动
服务器运维问答

PHP 7 and 5.6 parallel in Nginx

· 52CE 我爱测

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-scr…

问题原文

原帖链接 · Michael · CC BY-SA 3.0

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))

已采纳解答

原帖链接 · Richard Smith · CC BY-SA 3.0

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:

location ~ ^/vexim/.*\.php$ { ... }
location ~ \.php$ { ... }

Make sure that the /vexim location comes first as regex locations are ordered.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-02-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。