1、首先到:http:///去下載最新的nginx/Windows,這里我用的版本是:nginx/Windows-0.8.9
2、下載下來(lái)后只需要解壓縮到任意地方即可;
3、然后配置好你的PHP;
配置PHP的時(shí)候需要注意一下幾個(gè)參數(shù)和APACHE的可能不太一樣:
cgi.force_redirect = 0
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1
4、開(kāi)始配置/nginx/conf下的nginx.conf;
帖一下我的配置:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 88;
#監(jiān)聽(tīng)88端口,可以隨意更改;
server_name localhost;
charset utf-8;
#設(shè)置服務(wù)器的字符集
#access_log logs/host.access.log main;
location / {
#設(shè)置網(wǎng)站跟路徑;
root E:/root;
#默認(rèn)網(wǎng)頁(yè)文件;
index index.html index.htm index.php;
#如果沒(méi)有頁(yè)面的話,那么列出文件夾資源;
autoindex on;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#設(shè)置錯(cuò)誤頁(yè)面;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ /.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#配置PHP最關(guān)鍵的地方:
location ~ /.php$ {
#root E:/root;
#配置監(jiān)聽(tīng)端口,需要和PHP-CGI的端口一樣;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#這個(gè)是設(shè)置路徑的,應(yīng)該和root一樣(我沒(méi)有試過(guò)不一樣什么效果);
fastcgi_param SCRIPT_FILENAME E:/root$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
include fastcgi_params;
}
}
}
5、設(shè)置完成以后在CMD中輸入:start nginx;
6、然后進(jìn)入PHP文件夾,輸入:php-cgi.exe -b 127.0.0.1:9000 ;
7、可以寫一下自己的重啟批處理命令:tskill nginx,start nginx;
OK,應(yīng)該就可以了。