Nginx 是一個輕量級的高性能 Http WebServer,以事件驅動方式編寫,是以相比 Apache 而言,Nginx 更加穩定、性能更好,而且配置簡單,資源占用較低。
1. 安裝 Nginx
從 v0.7.52 開始,Nginx 開始釋出 Windows 版本的 Nginx,你可以在其官方網站上面下載下傳:http://nginx.net
下載下傳後直接解壓即可,這裡解壓縮到c:\nginx目錄。
2. 啟動Nginx
指令行進入c:\nginx目錄,運作nginx.exe,啟動控制台視窗。預設啟用80端口。用過Tomcat的人都希望能在控制台看到啟動日志,nginx的日志卻不得不檢視logs目錄下的相應log檔案。
3. 通路歡迎html頁
在浏覽器中通路http://localhost,可以看到預設的歡迎頁.
4. 停止Nginx
Ctrl+C沒反應。于是關閉控制台視窗。可是再通路http://localhost依然有效。檢視程序,發現nginx根本沒有被關閉。是以如果想徹底關閉nginx,應該是

nginx -s stop
或者使用windows的taskkill指令(推薦用下面的):

taskkill /F /IM nginx.exe > nul
5. Ngnix常用配置
Nginx的所有配置都預設使用conf/nginx.conf檔案,其地位相當于apache的httpd.conf檔案 。當運作nginx.exe暗含運作了nginx -c conf\nginx.conf. 如果想使用自己定義的conf檔案如my.conf,指令為nginx -c conf\my.conf.
常用配置如下:

http {
server {
#1.偵聽80端口
listen 80;
location / {
# 2. 預設首頁目錄在nginx安裝目錄的html子目錄。
root html;
index index.html index.htm;
# 3. 沒有索引頁時,羅列檔案和子目錄
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}
# 4.指定虛拟目錄
location /tshirt {
alias D:\programs\Apache2\htdocs\tshirt;
index index.html index.htm;
}
# 5.虛拟主機www.emb.info配置
listen 80;
server_name www.emb.info;
access_log emb.info/logs/access.log;
index index.html;
root emb.info/htdocs;
}
小提示:
運作nginx -V可以檢視該Win32平台編譯版支援哪些子產品。我這裡的結果為:

nginx version: nginx/0.7.65
TLS SNI support enabled
configure arguments:
--builddir=objs.msvc8
--crossbuild=win32
--with-debug --prefix=
--conf-path=conf/nginx.conf
--pid-path=logs/nginx.pid
--http-log-path=logs/access.log
--error-log-path=logs/error.log
--sbin-path=nginx.exe
--http-client-body-temp-path=temp/client_body_temp
--http-proxy-temp-path=temp/proxy_temp
--http-fastcgi-temp-path=temp/fastcgi_temp
--with-cc-opt=-DFD_SETSIZE=1024
--with-pcre=objs.msvc8/lib/pcre-7.9
--with-openssl=objs.msvc8/lib/openssl-0.9.8k
--with-openssl-opt=enable-tlsext
--with-zlib=objs.msvc8/lib/zlib-1.2.3
--with-select_module
--with-http_ssl_module
--with-http_realip_module
--with-http_addition_module
--with-http_sub_module
--with-http_dav_module
--with-http_stub_status_module
--with-http_flv_module
--with-http_gzip_static_module
--with-http_random_index_module
--with-http_secure_link_module
--with-mail
--with-mail_ssl_module
--with-ipv6
顯然,最經常用的memcache, rewrite子產品都沒在其中,是以該win32編譯版本僅能供基本開發測試使用,對于産品平台,應該重新編譯自己想要的win32版本,或者在linux下使用更友善。
如何聯系我:【萬裡虎】www.bravetiger.cn
【QQ】3396726884 (咨詢問題100元起,幫助解決問題500元起)
【部落格】http://www.cnblogs.com/kenshinobiy/