系统环境:
windows server 2003
PHP套件 xampp
1,首先,去掉nginx.conf文件中有关PHP配置的注释行
复制代码 代码示例:
# 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;
#}
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;
}
2,使用php cgi模式,所以要启用 php-cgi,修改 php.ini,把注释去掉:
复制代码 代码示例:
;cgi.fix_pathinfo=1
cgi.fix_pathinfo=1
3,启动 php-cgi 和 nginx
1)、start_nginx.bat
复制代码 代码示例:
@echo off
REM set PHP_FCGI_CHILDREN=5
set PHP_FCGI_MAX_REQUESTS=1000
echo Starting PHP FastCGI...
RunHiddenConsole D:/xampp/php/php-cgi.exe -b 127.0.0.1:9000 -c D:/xampp/php/php.ini
echo Starting nginx...
RunHiddenConsole D:/nginx/nginx.exe -p D:/nginx/
2)、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
可以查看进程中是否有nginx 和 php-cgi。
可能会遇到:"No input file specified" 的问题,需要修改文件 nginx.conf :
复制代码 代码示例:
location ~ .php$ {
#root html;
root D:/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME D:/nginx/html$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
注意,要将注释的地方,修改成下面那行,请根据具体文件配置路径。
创建测试文件test.php,内容如下:
复制代码 代码示例:
<?php
phpinfo();
?>
访问 http://localhost:81/test.php,测试正常。