配置Nginx同时支持PHP5.2+php5.3 + PHP5.6
这里我们采用php的fastcgi模式来配置nginx对php的支持
1)、首先打开nginx的配置文件目录 D:\Server\nginx\conf 找到nginx.conf 打开它, 我们需要先对他进行改造,以方便我们使用。
我们将server部分的默认配置全部注释掉,然后将server部分的配置全部转移至D:\Server\nginx\conf\vhost 目录[添加配置语句
include vhost/*.conf;
见图.
2)、在D:\Server\nginx\conf目录分别新建php52.conf php53.conf和php56.conf 配置文件 见图,对应的文件和内容如下:
D:\Server\nginx\conf\php52.conf
index default.html index.html index.htm default.php index.php;
location ~ .*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9052;
fastcgi_index index.php;
include fastcgi.conf;
}
D:\Server\nginx\conf\php53.conf
index default.html index.html index.htm default.php index.php;
location ~ .*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9053;
fastcgi_index index.php;
include fastcgi.conf;
}
D:\Server\nginx\conf\php56.conf
index default.html index.html index.htm default.php index.php;
location ~ .*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9056;
fastcgi_index index.php;
include fastcgi.conf;
}
说明: 这里的 127.0.0.1:90xx 是php所对应版本的监听地址和端口,此处设置的xx为本人最近定义的对应PHP版本的端口号,如9052表示的是PHP5.2版本[本人原创,不喜欢这个端口可设置任意你能记住的端口,当然这个端口必须是其他程序没有使用的]
3)、转到php目录配置PHP.ini
将对应的PHP版本的目录里面的php.ini-development改名为 php.ini 然后根据自己的实际使用需要配置就可以了,具体可百度搜索 “ PHP配置文件详解php.ini ”查看
4)、在D:\Server\nginx目录创建PHP的启动和关闭脚本
先创建ReStartNginx.bat 文件, 然后添加如下内容:
@ECHO OFF
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
echo ReStarting nginx...
ECHO Starting PHP FastCGI...
RunHiddenConsole D:/Server/php-5.2.13-nts-Win32/php-cgi.exe -b 127.0.0.1:9052 -c D:/Server/php-5.2.13-nts-Win32/php.ini
RunHiddenConsole D:/Server/php-5.3.29-nts-Win32-VC9-x86/php-cgi.exe -b 127.0.0.1:9053 -c D:/Server/php-5.3.29-nts-Win32-VC9-x86/php.ini
RunHiddenConsole D:/Server/php-5.6.4-nts-Win32-VC11-x86/php-cgi.exe -b 127.0.0.1:9056 -c D:/Server/php-5.6.4-nts-Win32-VC11-x86/php.ini
echo Starting nginx...
D:/Server/nginx/nginx.exe
exit
创建 stop.bat【关闭nginx和PHP服务的】文件,添加如下内容
@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit
完成以上步骤后,直接打开ReStartNginx.bat 大公告成! 可以开始你的NGINX+php多版本共存之旅了...............