第一步 下载nginx ,windows版本,解压保存在D:/nginx-1.0.4下( 用的1.0.4版)
第二步 下载 php fast-cgi版本(我用的是 VC9 x86 Non Thread Safe),解压到D:/php-5.3.3下
第三步 把D:/php-5.3.3./php.ini-development重命名成D:/php-5.3.3/php.ini,找到#cgi.fix_pathinfo=1,把#号去掉
第四步 修改D:/nginx-1.0.4/conf/nginx.conf
下面是我的简单配置:
#usernobody;
worker_processes1;
#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
#pidlogs/nginx.pid;
events{
worker_connections1024;
}
http{
includemime.types;
default_typeapplication/octet-stream;
#log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'
#'$status$body_bytes_sent"$http_referer"'
#'"$http_user_agent""$http_x_forwarded_for"';
#access_loglogs/access.logmain;
sendfileon;
#tcp_nopushon;
#keepalive_timeout0;
keepalive_timeout65;
#gzipon;
server{
listen80;
server_namelocalhost;
#charsetkoi8-r;
#access_log logs/host.access.log main;
#增加负载配置,单机以不同端口方式配置
upstream localhost {
server127.0.0.1:8080weight=2;
server127.0.0.1:8081weight=1;
}
location/{
#roothtml;//此处为默认路径
rootD:/PHPWeb;//此处为我修改,要运行PHP程序的路径
index index.php index.html index.htm; //增加了 index.php#以下配置为服务器负载时进行的配置
proxy_passhttp://localhost;
proxy_set_headerHost$host;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
}
#error_page404/404.html;
#redirectservererrorpagestothestaticpage/50x.html
#
error_page500502503504/50x.html;
location=/50x.html{
roothtml;
}
#proxythePHPscriptstoApachelisteningon127.0.0.1:80
#
#location~\.php${
#rootphp;
#indexindex.php
#proxy_passhttp://127.0.0.1;
#}
#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000
#
location~\.php${
rootD:/PHPWeb;//运行的PHP程序路径
fastcgi_pass127.0.0.1:9000;
fastcgi_index index.php; //默认首页程序#$document_root 指的是上面的 D:/PHPWeb fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#denyaccessto.htaccessfiles,ifApache'sdocumentroot
#concurswithnginx'sone
#
#location~/\.ht{
#denyall;
#}
}
#anothervirtualhostusingmixofIP-,name-,andport-basedconfiguration
#
#server{
#listen8000;
#listensomename:8080;
#server_namesomenamealiasanother.alias;
#location/{
#roothtml;
#indexindex.htmlindex.htm;
#}
#}
#HTTPSserver
#
#server{
#listen443;
#server_namelocalhost;
#sslon;
#ssl_certificatecert.pem;
#ssl_certificate_keycert.key;
#ssl_session_timeout5m;
#ssl_protocolsSSLv2SSLv3TLSv1;
#ssl_ciphersALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
#ssl_prefer_server_cipherson;
#location/{
#roothtml;
#indexindex.htmlindex.htm;
#}
#}
}第五步、PHP以fast-cgi形式运行
启动PHP fastcgi执行环境,我们编写bat文件来启动Nginx和PHP的fastcgi
新建记事本,写入如下内容:
@echo off
start D:\php-5.3.3\php-cgi.exe -b 127.0.0.1:9000 -c D:\php-5.3.3\php.ini
start D:\nginx-1.0.4\nginx.exe
将此记事本改名为test.bat;
双击bat文件,即可启动Nginx和PHP的fastcgi