1. 在nginx官方網站下載下傳nginx的zip包 http://nginx.org/download/nginx-0.8.52.zip
2. 解壓在d:/nginx
3. 在d:/nginx下建立兩個.bat檔案,用于啟動和結束nginx
以下是start-nginx.bat
@ECHO Off
@ECHO Starting PHP FastCGI...
d:/xampp/php/RunHiddenConsole.exe d:/xampp/php/php-cgi.exe -b 127.0.0.1:9000 -c d:/xampp/php/php-cgi/php.ini
@ECHO PHP FastCGI Started
@ECHO Starting Nginx...
d:
cd d:/nginx/
start nginx
@ECHO ______________________________________________________________________
@ECHO Nginx Service Status:
tasklist /FI "IMAGENAME eq nginx*"
@ECHO ______________________________________________________________________
@ECHO PHP-CGI Service Status:
tasklist /FI "IMAGENAME eq php-cgi*"
pause
以下是stop-nginx.bat
@ECHO Off
taskkill /f /im php-cgi.exe
taskkill /f /im nginx.exe
4. 修改d:/nginx/conf/nginx.conf
#worker_processes 8; #windows下要注釋掉,否則不傳回結果
error_log logs/nginx_error.log;
pid logs/nginx.pid;
worker_rlimit_nofile 51200;
events {
#use epoll;
worker_connections 51200;
}
http {
include mime.types;
default_type application/octet-stream;
charset UTF-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
#gzip on;
#gzip_min_length 1k;
#gzip_buffers 4 16k;
#gzip_http_version 1.0;
#gzip_comp_level 2;
#gzip_types text/plain application/x-javascript text/css application/xml;
#gzip_vary on;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name yii.webteam.com;
root D:/yourPath;
error_page 404 = /404.php;
index index.php
access_log logs/yii.access.log combined;
error_log logs/yii.error.log;
location ~ /.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_intercept_errors on;
include fastcgi.conf;
}
location ~* ^.+/.(jpg|jpeg|gif|css|js|xml|swf|png|ico|html)$ {
expires max;
}
}
}
注意:
nginx.conf中server_name不可以配置中文,否則.php檔案可以通路,但是.css等檔案通路會出500錯誤,日志中顯示:
No mapping for the Unicode character exists in the target multi-byte code page
至此,完成nginx的安裝
==========================================================
PHP安裝我比較偷懶,直接使用xampp,下載下傳位址:http://www.apachefriends.org/zh_cn/xampp.html
下載下傳後解壓縮到d:/xampp
還要下載下傳一個RunHiddenConsole.exe,下載下傳位址:http://www.box.net/shared/vfvqyjhday
用于運作時隐藏dos控制台.放到 d:/xampp/php/RunHiddenConsole.exe
==========================================================
輕按兩下d:/nginx/start-nginx.bat運作nginx
寫一個phpinfo();測試,運作良好