Nginx系列教程:nginx_substitutions_filter模塊

nginx_substitutions_filter css

請注意:此模塊不是Nginx源的分佈,可點擊此連接找到安裝說明, html

http://wiki.nginx.org/NginxHttpSubsModule#Installation 。 linux

概述 nginx

nginx_substitutions_filter 是一個過濾器模塊,它能夠在響應主體上運行正則表達式和固定字符串替換。該 正則表達式

模塊不一樣於Nginx的本地替代模塊。它可以掃描輸出鏈緩衝區和匹配逐行字符串,相似於Apache的 svn

mod_substitute。 優化

好比 google

location / {
 
    subs_filter_types text/html text/css text/xml;
    subs_filter st(\d*).example.com $1.example.com ir;
    subs_filter a.example.com s.example.com;
 
} spa

指令 代理

•subs_filter_types 
•subs_filter

subs_filter_types

語法: subs_filter_types mime-type [mime-types] 
默認值: subs_filter_types text/html 
做用域: http, server, location

subs_filter_types 用於指定subs_filter的內容類型檢查。默認是text/html.。

該模塊只適用於純文本。若是是壓縮的響應,它不能解壓縮響應,且將忽略此響應。這個模塊能夠兼容gzip過濾

器模塊。可是不能代理壓縮的響應,您能夠禁用這樣的壓縮響應,以下:
proxy_set_header Accept-Encoding "";

subs_filter

語法: subs_filter source_str destination_str [gior] 
默認值: none 
做用域: http, server, location 
subs_filter 容許在目標字符串的nginx響應中替換源字符串(正則表達式或固定)。替代的文本可能包含變量

。支持每一個位置一個以上的替換規則。第三個標誌的含義是:
•g(default): 替換全部匹配字符串。
•i: 執行區分大小寫的匹配。 
•o: 只替換第一個。
•r: 處理模式是做爲一個正規表達式,默認是固定的字符串。

安裝說明

安裝前,先獲取SVN版本控制源:

svn checkout http://substitutions4nginx.googlecode.com/svn/trunk/ substitutions4nginx-read-only
 
而後編譯nginx的下列選項:

./configure --add-module=/path/to/module

更新說明

nginx_substitutions_filter 0.5.2 2010-08-11 更新

•進行了多個模塊的優化
•修復了緩衝區重疊的錯誤
•修復了輸出鏈迴歸NGX_AGAIN的段故障錯誤
•修復了最後沒有換行緩衝區的錯誤,這將會導至段故障。

nginx_substitutions_filter 0.5 2010-04-15 更新

•重構源結構,建立dev分支。
•修復了緩衝區塊形成內容遺失的錯誤
•修復了last_buf的錯誤和兼容nginx 0.8.25版本以上的錯誤
•修復了固定字符串替換中不須要的配置錯誤
•添加正規表達式捕獲功能

nginx_substitutions_filter 0.4 2009-12-23 更新

•修復了多個漏洞
nginx_substitutions_filter 0.3 2009-02-04 更新
•首次公開發布

相關文章
相關標籤/搜索