分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

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

发布时间:2023-09-06 02:26责任编辑:顾先生关键词:nginxhttp编译
最近有个需求:需要过滤替换掉网站上部分内容,查了下资料NGINX自带过滤功能模块,于是实践了下,具体操作如下:
虽然是NGINX自带了with-http_sub_module模块,但是需要编译安装NGINX,并指定选项才可以正常使用。
需要编译安装NGINX(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

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


多站点测试:建立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;
}
}


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

访问测试效果:

测试结果:1、sub_filter只支持单行,功能有限(加多行会报错)。
2、subs_filter支持多行过虑,且支持正则,功能较强大。

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

原文地址:http://blog.51cto.com/jdonghong/2331906

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved