新聞中心
中文文檔
Nginx 功能概述
--|Http 基礎(chǔ)功能:
1. 處理靜態(tài)文件
2. 反向代理加速(無緩存),簡(jiǎn)單的負(fù)載均衡和容錯(cuò)。
3. 模塊化結(jié)構(gòu)
4. SSL 和TLS SNI支持
--|IMAP/POP3代理服務(wù)功能:
--|其他Http 功能:
1. 基于IP和名稱的虛擬主機(jī)服務(wù)
2. 基于客戶端IP地址和HTTP基本認(rèn)證的訪問控制
3.支持FLV(Flash視頻)
補(bǔ)充:Nginx 可以作為Web服務(wù)器、負(fù)載均衡服務(wù)器、郵件代理服務(wù)器。
其中,我使用它作為Tomcat的HTTP代理服務(wù)器。
Nginx主模塊
include
配置文件的包含:
include vhosts/*.conf;
http 核心模塊
alias
location /i/ { alias /spool/w3/images/; }
表示請(qǐng)求"/i/top.gif"將返回文件: "/spool/w3/images/top.gif".
default_type
指定標(biāo)準(zhǔn)MIME-type以外的MIME 類型。
location = /proxy.pac { default_type application/x-ns-proxy-autoconfig; }
index
指定index 的文件
internal
error_page 404 /404.html; location /404.html { internal; }
此位置只處理"internal"請(qǐng)求,如:
requests redirected by the instructionerror_page
subrequests created by the commandinclude virtualof the "ngx_http_ssi_module" module
requests changed by the instructionrewriteof the "ngx_http_rewrite_module" module
Nginx 0.7.x 引入了新的internal locations:@Location
location / { root /var/www/html; error_page 404 @40x; } location @40x { root /var/www/errors/40x.html; }
location
1. ~*大小寫不敏感
2. ~ 大小寫敏感
匹配順序:
~先匹配一部分query,搜索不停止。
然后搜索正則,正則匹配了,就停止搜索。
如果沒有正則匹配,則搜索字面量。
匹配修正:
“=” 前綴:僅匹配額外的query,如果匹配則搜索停止。比如query - ”/"頻繁出現(xiàn),可以使用"location = /" 去處理這類請(qǐng)求。
"^~"前綴:表示部分匹配后不再繼續(xù)搜索。比如"location ^~/images/",表示以 "/images"開頭的 query 即匹配此location,不再繼續(xù)搜索正則。
location = / { # matches the query / only. [ configuration A ] } location / { # matches any query, since all queries begin with /, but regular # expressions and any longer conventional blocks will be # matched first. [ configuration B ] } location ^~ /images/ { # matches any query beginning with /images/ and halts searching, # so regular expressions will not be checked. [ configuration C ] } location ~* .(gif|jpg|jpeg)$ { # matches any request ending in gif, jpg, or jpeg. However, all # requests to the /images/ directory will be handled by # Configuration C. [ configuration D ] }
針對(duì)上述配置,可能的匹配結(jié)果:
/ -> configuration A
/documents/document.html -> configuration B
/images/1.gif -> configuration C
/documents/1.jpg -> configuration D
root
location /i/ { root /spool/w3; }
比如對(duì)于 請(qǐng)求"/i/top.gif" 將返回文件"/spool/w3/i/top.gif". 注意比較alias,這里會(huì)匹配"i"目錄到query中。
server
配置 virtual server
指令listen 用于配置 addresses和ports
指令server_name用于配置 server_name
注意:如果 host和server都匹配的話,host將匹配。
server的搜索順序:
全名
前通配符 *.example.com
后通配符 — www.example.*
正則匹配
types
types { text/html html; image/gif gif; image/jpeg jpg; }
The sufficiently complete table of mappings is included and is located in the file conf/mine.types
匹配所有類型,可以使用 types { }
location /download/ { types { } default_type application/octet-stream; }
變量
支持apache 內(nèi)置變量,如:$http_user-agent,$http_cookie,and so forth.
還支持
$arg_PARAMETER 表示GET 請(qǐng)求的中變量PARAMETER的值。
$args/$query_string 請(qǐng)求行的參數(shù)
$content_length
$content_type
$cookie_COOKIE
$document_root 效果等同于root指令,但只針對(duì)當(dāng)前請(qǐng)求。
$document_uri/$uri
$host 等同于,用于 host頭不可得時(shí)。
$http_HEADER
...
HttpProxy模塊
此模塊專伺將請(qǐng)求導(dǎo)向其它服務(wù).
It is an HTTP/1.0 proxy without the ability for keep-alive requests yet.
補(bǔ)充:無請(qǐng)求保持,可能需要多次建立Tcp連接。無連接的含義是限制每次連接只處理一個(gè)請(qǐng)求。服務(wù)器處理完客戶的請(qǐng)求,并收到客戶的應(yīng)答后,即斷開連接。采用這種方式可以節(jié)省傳輸時(shí)間。
HTTP 協(xié)議是無狀態(tài)協(xié)議。無狀態(tài)是指協(xié)議對(duì)于事務(wù)處理沒有記憶能力。缺少狀態(tài)意味著如果后續(xù)處理需要前面的信息,則它必須重傳,這樣可能導(dǎo)致每次連接傳送的數(shù)據(jù)量增大。服務(wù)器沒有保存客戶端的狀態(tài)信息吧,客戶端必須每次帶上自己的狀態(tài)去請(qǐng)求服務(wù)器(比如cookie、session等)。另一方面,在服務(wù)器不需要先前信息時(shí)它的應(yīng)答就較快。
示例 location / { : proxy_pass http://localhost:8000; : proxy_set_header X-Real-IP $remote_addr; }
網(wǎng)頁(yè)標(biāo)題:Nginx文檔閱讀記錄
標(biāo)題路徑:http://www.ef60e0e.cn/article/cpjges.html