nginx编译安装WEB站点内容过滤功能模块(with-http_sub_module)

栏目: 服务器 · Nginx · 发布时间: 7年前

内容简介:./configure \--prefix=/application/nginx-1.6.3 \--user=nginx \

最近有个需求:需要过滤替换掉网站上部分内容,查了下资料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

;

;

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支持多行过虑,且支持正则,功能较强大。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

互联网+供应链金融创新

互联网+供应链金融创新

宝象金融研究院、零壹研究院 / 电子工业出版社 / 2016-6 / 65.00

供应链金融是一种带有模式创新的金融服务,它真正渗透到了产业运行的全过程。然而,如何探索这种模式的规律?特别是在"互联网+”时代,不同的产业主体如何更好地利用供应链金融促进产业的发展,成为了众多企业关注的话题。零壹财经攥写的《互联网+供应链金融创新》正是立足于这一点,全面总结反映了中国各行各业,以及不同的经营主体如何在立足产业运营的基础上,通过供应链金融来促进产业的发展具有很好的借鉴意义,其丰富的案......一起来看看 《互联网+供应链金融创新》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具