Windows下Nginx+php环境搭建
++++++++++++++++++++++++++++++++++++++++++++++
操作系统 : [windows xp professional sp3]
服务器 : [nginx-0.8.21]
PHP : [php-5.2.17]
++++++++++++++++++++++++++++++++++++++++++++++
准备安装软件(download)
1> [nginx-0.8.21]
http://sysoev.ru/nginx/nginx-0.8.21.zip
2> [php-5.2.17-Win32-VC6-x86]
http://windows.php.net/downloads/releases/php-5.2.17-Win32-VC6-x86.zip
3> [服务注册工具(srvany.exe, instsrv.exe)]
http://download.csdn.net/detail/zy27ok/2248126
4> [RunHiddenConsole-Windows下隐藏DOS命令行窗口的程序]
http://ishare.iask.sina.com.cn/f/16990002.html
++++++++++++++++++++++++++++++++++++++++++++++
开始安装(安装前建立目录[D:/lamp])
D:/lamp
--nginx
--php
--sites
----------------------------------------------------------------------------
1>【nginx】
1.1> 将nginx-0.8.21.zip解压到[D:/lamp/nginx]中
1.2> 将nginx安装到windows服务中
1.2.1>下载微软服务注册工具srvany.exe, instsrv.exe存放到D:/lamp/nginx/目录下
1.2.2>安装Nginx服务, 将命令行切换到D:/lamp/nginx/,执行下列命令
instsrv NGINX D:\lamp\nginx\srvany.exe
1.2.3>在D:/lamp/nginx/下,新建一个nginx.reg文件,输入一下内容:Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NGINX\Parameters]
"Application"="D:/lamp/nginx/nginx.exe"
"AppParameters"=""
"AppDirectory"="D:/lamp/nginx/"
1.2.4>让服务与程序关联起来,命令行执行regedit /s nginx.reg2>【php】
2.1> 将php-5.2.17-Win32-VC6-x86.zip解压到[D:/lamp/php]
3>【php配置】
3.1> php.ini
3.1.1> D:/lamp/php/php.ini, 复制php.ini-recommended并重命名为php.ini
3.1.2>
#功能: 指定扩展库所在目录
extension_dir = "D:/lamp/php/ext/"
#功能: 开启扩展#说明: 根据需要开启相应扩展模块, 去掉前前面的分号
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mcrypt.dll
extension=php_mysql.dll
extension=php_mysqli.dll
#功能: 设置时区#说明: PRC表示中国
date.timezone = PRC
#功能: 显示错误信息display_errors = On
#功能: cgi相关 enable_dl = On
cgi.force_redirect = 0
cgi.fix_pathinfo=1
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1
3.2>复制php5ts.dll, libmysql.dll, libmcrypt.dll(D:/lamp/php)到C:/WINDOWS/system32/4>【nginx配置】
4.1>在server下找到location / 修改解析PHP文件存放的路径, 修改为:
location / {
root D:/lamp/sites;
index index.html index.htm index.php;
}
root表示虚拟目录设置为D:/lamp/sites,增加默认解析index.php4.2>在server下找到location ~ /.php$ 修改php解释器FastCGI配置,修改为:
location ~ \.php$ {
root D:/lamp/sites;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME D:/lamp/sites$fastcgi_script_name;
include fastcgi_params;
}
5>【用命令行启动或终止php-cgi和进程】5.1>下载RunHiddenConsole:用来隐藏dos窗口
5.2>启动php-cgi,新建一个bat文件,如start.bat,用记事本打开,并编写如下代码:
@echo off
echo Starting PHP FastCGI...
RunHiddenConsole.exe D:/lamp/php/php-cgi.exe -b 127.0.0.1:9000 -c D:/lamp/php/php.ini
5.3>终止php和nginx进程,如stop.bat,同样用记事本打开,并编写如下代码:@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit
6>【nginx基于域名的虚拟主机配置】
6.1>在http最后一行加入
include D:/lamp/nginx/conf/vhost/dev_localhost.config;
6.2>不带url重写:D:/lamp/nginx/conf/vhost/dev_localhost.config
server {
listen 80 default;
server_name dev.localhost;
access_log logs/dev.access.log;
root D:/lamp/sites/dev;
server_name_in_redirect off;
location / {
index index.html index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
6.3>带url重写(zend framework)D:/lamp/nginx/conf/vhost/dev_localhost.config
server {
listen 80;
server_name dev.localhost;
access_log logs/dev.access.log;
root D:/lamp/sites/dev/code/html;
location / {
index index.html index.php;
if (-e $request_filename ) {
break;
}
if ( $request_filename ~* \.(js|ico|gif|jpg|jpeg|xml|swf|txt|png|css|html|htm)$ ) {
return 404;
}
rewrite .* index.php;
}
location ~ .*\.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
#fastcgi_param REQUEST_URI $document_uri?$query_string;
fastcgi_read_timeout 120;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
}