茫茫網海中的冷日 - 對這文章發表回應
茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1674226 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
LSxMF_00047.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

對這文章發表回應

發表限制: 非會員 可以發表

發表者: 冷日 發表時間: 2018/12/20 10:24:06

Nginx 教程一:在windows環境下的安裝、配置、使用以及設置為windows服務自啟動

目前國內各大門戶網站已經部署了Nginx,如新浪、網易、騰訊等;國內幾個重要的視頻分享網站也部署了Nginx,如六房間、酷6等。新近發現Nginx 技術在國內日趨火熱,越來越多的網站開始部署Nginx。

相比apeach、iis,nginx以輕量級、高性能、穩定、配置簡單、資源佔用少等優勢廣受歡迎。

下載地址:

   http://nginx.org

啟動

  解壓至c:\nginx,運行nginx.exe(即nginx -c conf\nginx.conf),默認使用80端口,日誌見文件夾C:\nginx\logs; 若nginx.exe啟動一閃而過,則需要修改nginx.conf中的默認端口

使用

   http://localhost:端口

關閉

  nginx -s stop 或taskkill /F /IM nginx.exe > nul

常用配置

  C:\nginx\conf\nginx.conf,使用自己定義的conf文件如my.conf,命令為nginx -c conf\my.conf


  常用配置如下:
  Nginx.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配置
   server {
   listen 80;
   server_name www.emb.info;
   access_log emb.info/logs/access.log;
   location / {
   index index.html;
   root emb.info/htdocs;
   }
   }
  }
  
  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配置
   server {
   listen 80;
   server_name www.emb.info;
   access_log emb.info/logs/access.log;
   location / {
   index index.html;
   root emb.info/htdocs;
   }
   }
  }
  
  小提示:
  運行nginx -V可以查看該Win32平台編譯版支持哪些模塊。我這裡的結果為:
  Log代碼
  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
  
  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下使用更方便。


簡單原理

配置文件基本結構就是這樣子,由若干指令(directives)構成。指令分為簡單指令(siple directives)和塊指令(block directives)。


簡單指令由指令名和參數構成,指令名和參數以空格分隔,每條指令以分號結尾。例如

user nginx;

這就是一條簡單指令,表示以 nginx 這個用戶身份運行 nginx 工作進程。指令名為 user ,參數為 nginx,最後分號結束。


塊指令由指令名和若干由花括號{}包圍起來的一組指令組成。例如

events {

worker_connections 1024;

}

就是一個塊指令,指令名為 events,後面緊跟 {} 包圍起來的一組指令。

如果一個塊指令內有其他指令,那麼這個塊指令也成為上下文(context),不在任何上下文中的指令被認為是在主上下文中(main context)。例如 events 和 http 位於主上下文中,server 位於 http 上下文中,location 則位於 server 上下文中。

以井號#開頭的行是註釋行,不起作用。

查看nginx進程

映像名稱 PID 會話名 會話# 內存使用
========================= ======== ================ =========== ============
nginx.exe 8944 Console 1 5,128 K
nginx.exe 6712 Console 1 5,556 K

nginx常用命令


nginx -s stop 強制關閉
nginx -s quit 安全關閉
nginx -s reload 改變配置文件的時候,重啟nginx工作進程,來時配置文件生效
nginx -s reopen 打開日誌文件

nginx設置為windows自啟動

每次手動啟動和關閉nginx.exe比較麻煩,因此可以在 windows系統下將nginx作為系統服務啟動。

a . 準備工作


下載安裝nginx,並記住安裝目錄 官網下載

下載winsw, 下載地址 (http://www.cr173.com/soft/101797.html)

b. winsw設置

將winsw可執行程序複製到nginx安裝目錄下,並重命名為nginx-service

新建名為nginx-service.xml的文件(註:文件名必須與可執行文件名相同)

並編輯如下,其中name為 服務名,executable為可執行程序路徑,logpath為程序運行日誌路徑

[html] view plain copy
  1. < service >
  2. < id > nginx </ id >
  3. < name > nginx </ name >
  4. < description > nginx </ description >
  5. < executable > E:\phpStudy\nginx\nginx.exe </ executable >
  6. < logpath > E:\phpStudy\nginx\ </ logpath >
  7. < logmode >
    roll </ logmode >
  8. < depend > </ depend >
  9. < startargument > -p E:\phpStudy\nginx </ startargument >
  10. < stopargument > -p E:\phpStudy\nginx -s stop </ stopargument >
  11. </ service >

如下:

c. 安裝服務

在nginx安裝目錄下運行cmd(快捷方式:shift + 鼠標右鍵),運行命令:nginx-service.exe install


註:nginx-service.exe uninstall命令可刪除對應的系統服務

nginx-service.exestop 命令可停止 對應的系統服務

nginx-service.exe start命令可啟動對應的系統服務

d. 查看服務是否安裝成功

計算機管理 -> 服務


如服務為未運行狀態,可在此啟動服務,或設置為自動啟動

註:若服務安裝成功,可在cmd(管理員身份)中對服務進行如下操作

啟動nginx :net start nginx

停止nginx:net stop nginx

e. 驗證nginx是否正常運行

在瀏覽器中打開網址http://localhost

原文地址:http://www.cnblogs.com/chuncn/archive/2011/10/14/2212291.html



原文出處:Nginx 教程一:在windows环境下的安装、配置、使用以及设置为windows服务自启动 - Aeroleo的博客 - CSDN博客
內容圖示
url email imgsrc image code quote
樣本
bold italic underline linethrough   












 [詳情...]
validation picture

注意事項:
預覽不需輸入認證碼,僅真正發送文章時才會檢查驗證碼。
認證碼有效期10分鐘,若輸入資料超過10分鐘,請您備份內容後,重新整理本頁並貼回您的內容,再輸入驗證碼送出。

選項

Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|