在windows下进行nginx +php的配置比较简单:
1、首先下载安装php,版本至少要在5.0以上(主要是要PHP版本支持FastCgi方式,包含有php-cgi.exe即可 ),修改php.ini配置文件
enable_dl = On
cgi.force_redirect = 1
cgi.fix_pathinfo=1
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1
rror_reporting = E_ALL
display_errors = On
extension_dir = "C:\php\ext"
; 动态扩展,可以根据需要去掉 extension 前面的注释 ;
; 如加载 PDO, MySQL
extension=php_pdo.dll
extension=php_pdo_mysql.dll
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll
2、Nginx配置PHP是以FastCgi方式配置的
3、用文本编辑功能根据打开E:\nginx1.0\conf 目录下的nginx.conf,找到
location / {
root html;
index index.html index.htm;
}
修改为
location / {
root D:/PHPWeb;
index index.php index.html index.htm;
}
找到
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
修改为
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME D:/PHPWeb$fastcgi_script_name;
include fastcgi_params;
}
4、启动fast-cgi
找到php的安装目录,在控制台输入以下命令
f:/php/php-cgi.exe -b 127.0.0.1:9000 -c f:/php/php.ini
5、找到nginx的安装目录,启动nginx
或者建立bat文件启动fast-cgi和nginx,
首先下载RunHiddenConsole.exe,附件提供下载
建立start_nginx.bat,输入以下内容:
@echo off
echo Starting PHP FastCGI...
RunHiddenConsole f:/php/php-cgi.exe -b 127.0.0.1:9000 -c f:/php/php.ini
echo Starting nginx...
d:/nginx1.0/nginx.exe
其中 127.0.0.1:9000 一定要和nginx.conf里的 fastcgi_pass 127.0.0.1:9000;要完全一致,否则会出现错误
建立stop_nginx.bat,输入以下内容:
@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit
在配置完成后,在D:/PHPWeb的目录下新建index.php文件,内容如下:
<?php
phpinfo();
?>
在ie地址栏里输入http://localhost/index.php,如果出现php的相关信息,则配置成功