nginx編譯安裝WEB站點內容過濾功能模塊(with-http_sub_module)

最近有個需求:需要過濾替換掉網站上部分內容,查了下資料NGINX自帶過濾功能模塊,於是實踐了下,具體操作如下:
雖然是NGINX自帶了with-http_sub_module模塊,但是需要編譯安裝NGINX,並指定選項纔可以正常使用。
需要編譯安裝NGINX(with-http_sub_module):
nginx編譯安裝WEB站點內容過濾功能模塊(with-http_sub_module)

./configure \
--prefix=/application/nginx-1.6.3 \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_stub_status_module \
--without-http_gzip_module \
--with-http_sub_module

譯安裝NGINX:(ngx_http_substitutions_filter_module)
此模塊需要先單獨下載
下載地址:git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git
nginx編譯安裝WEB站點內容過濾功能模塊(with-http_sub_module)

./configure \
--prefix=/application/nginx-1.6.3 \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_stub_status_module \
--without-http_gzip_module \
--with-http_sub_module \
--add-module=/application/ngx_http_substitutions_filter_module #指定模塊路徑

測試過程:建立測試站
配置文件如下:
[root@k8s conf]# cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
sub_filter nginx apache;
server {
listen 80;
server_name www.nginx.com;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

nginx編譯安裝WEB站點內容過濾功能模塊(with-http_sub_module)
多站點測試:建立vhosts目錄(多站點配置incule vhosts/*導入)

Bbs.conf :
server {
listen 80;
server_name bbs.nginx.com;
location / {
root /data/wwwroot/bbs;
index index.html index.htm;
}
}
Blogs.conf:
server {
listen 80;
server_name blogs.nginx.com;
location / {
root /data/wwwroot/blogs;
index index.html index.htm;
}
}

nginx編譯安裝WEB站點內容過濾功能模塊(with-http_sub_module)
[root@k8s conf]# cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
subs_filter nginx apache;
subs_filter If apache;
subs_filter com cn;
subs_filter_types ;
include vhosts/
;
server {
listen 80;
server_name www.nginx.com;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
nginx編譯安裝WEB站點內容過濾功能模塊(with-http_sub_module)

訪問測試效果:
nginx編譯安裝WEB站點內容過濾功能模塊(with-http_sub_module)

測試結果:1、sub_filter只支持單行,功能有限(加多行會報錯)。
2、subs_filter支持多行過慮,且支持正則,功能較強大。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章