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

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

./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

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

./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 #指定模塊路徑github

測試過程:創建測試站
配置文件以下:
[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;
}
}
}apache

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

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;
}
}ide

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)網站

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

相關文章
相關標籤/搜索