Nginx - Windows下Nginx基本安裝和配置

來源:互聯網
上載者:User

標籤:

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,應該是 

Command代碼  
  1. nginx -s stop  


請參考官方文檔nginx/Windows usage 
或者使用windows的taskkill命令(推薦用下面的): 

Command代碼  
  1. 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. 
常用配置如下: 

Nginx.conf代碼  
  1. http {  
  2.   server {  
  3.     #1.偵聽80連接埠   
  4.     listen  80;   
  5.     location / {  
  6.         # 2. 預設首頁目錄在nginx安裝目錄的html子目錄。  
  7.         root   html;  
  8.         index  index.html index.htm;  
  9.         # 3. 沒有索引頁時,羅列檔案和子目錄  
  10.         autoindex on;  
  11.         autoindex_exact_size on;  
  12.         autoindex_localtime on;  
  13.     }  
  14.     # 4.指定虛擬目錄  
  15.     location /tshirt {  
  16.     alias D:\programs\Apache2\htdocs\tshirt;  
  17.     index index.html index.htm;  
  18.     }  
  19.   }  
  20.   # 5.虛擬機器主機www.emb.info配置  
  21.   server {  
  22.     listen          80;  
  23.     server_name     www.emb.info;  
  24.     access_log emb.info/logs/access.log;  
  25.     location / {  
  26.       index index.html;  
  27.       root  emb.info/htdocs;  
  28.     }  
  29.   }  
  30. }  



小提示: 
運行nginx -V可以查看該Win32平台編譯版支援哪些模組。我這裡的結果為: 

Log代碼  
  1. nginx version: nginx/0.7.65  
  2. TLS SNI support enabled  
  3. configure arguments:   
  4. --builddir=objs.msvc8   
  5. --crossbuild=win32   
  6. --with-debug --prefix=   
  7. --conf-path=conf/nginx.conf   
  8. --pid-path=logs/nginx.pid   
  9. --http-log-path=logs/access.log   
  10. --error-log-path=logs/error.log   
  11. --sbin-path=nginx.exe   
  12. --http-client-body-temp-path=temp/client_body_temp   
  13. --http-proxy-temp-path=temp/proxy_temp   
  14. --http-fastcgi-temp-path=temp/fastcgi_temp   
  15. --with-cc-opt=-DFD_SETSIZE=1024   
  16. --with-pcre=objs.msvc8/lib/pcre-7.9   
  17. --with-openssl=objs.msvc8/lib/openssl-0.9.8k   
  18. --with-openssl-opt=enable-tlsext   
  19. --with-zlib=objs.msvc8/lib/zlib-1.2.3   
  20. --with-select_module   
  21. --with-http_ssl_module   
  22. --with-http_realip_module   
  23. --with-http_addition_module   
  24. --with-http_sub_module   
  25. --with-http_dav_module   
  26. --with-http_stub_status_module   
  27. --with-http_flv_module   
  28. --with-http_gzip_static_module   
  29. --with-http_random_index_module   
  30. --with-http_secure_link_module   
  31. --with-mail   
  32. --with-mail_ssl_module   
  33. --with-ipv6  


顯然,最經常用的memcache, rewrite模組都沒在其中,因此該win32編譯版本僅能供基本開發測試使用,對於產品平台,應該重新編譯自己想要的win32版本,或者在linux下使用更方便。 

Nginx - Windows下Nginx基本安裝和配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.