Nginx编译安装第三方模块http_substitutions_filter_module
Nginx编译安装第三方模块http_substitutions_filter_module 分类:服务器技术 作者:rming 时间:--
. >>ngx_http_substitutions_filter_module OR HttpSubModule ? 为了应急处理或者一些需要,有时候需要使用Nginx的反向代理某站点,并通过 HttpSubModule 和ngx_http_substitutions_filter_module 模块替换正文内容和URL。
但是通常LNMP套件安装的webserver并没有编译安装nginx官方模块HttpSubModule(官方option),并且,官方自带的模块HttpSubModule 只能匹配1条规则,但是使用第三方模块ngx_http_substitutions_filter_module 可以匹配多条规则。 备注:
ngx_http_substitutions_filter_module 是指第三方nginx模块 substitutions4nginx (原:Google Code 现:github)
HttpSubModule 是指Nginx官方的 with-http_sub_module模块(option) Nginx自身带的module并不多,这也是它为什么性能好,系统开销较小的原因之一,相比apache,它不能动态的加载module,如果之前编译安装了Nginx,这时候就需要重新编译nginx添加模块,并替换掉原先的nginx执行文件。 . .下载需要的文件 substitutions4nginx github下载 # 下载第三方模块
# cd ~
# git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git
. .查看之前Nginx编译configure # nginx -V
nginx version: nginx/1.2.
built by gcc 4.6. (Ubuntu/Linaro 4.6.-1ubuntu5)
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with- http_ssl_module --with-http_gzip_static_module --with-ipv6
因为Nginx编译安装第三方模块的时候需要添加上之前编译的configure参数,然后重新设置configure编译(但是不覆盖安装,只make不install): ./configure --prefix=/你的安装目录 --add-module=/第三方模块目录
. .重新编译Nginx # 打开Nginx编译目录,版本号可能不同
# cd ~/lnmp1.-full/nginx-1.2.
# 重新configure
# ./configure --prefix= --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --add-module=/root/ngx_http_substitutions_filter_module
# make
备注:重新编译的时候,记得一定要把以前编译过的模块一同加到configure参数里面. . .覆盖原nginx文件 # /etc/init.d/nginx stop
# cd cd objs/
# 覆盖原文件
# cp nginx /usr/local/nginx/sbin/
# /etc/init.d/nginx start
. .简单配置 . ① HttpSubModule 的 官方文档 说的很清楚,这里就不写实例了,并且功能没有substitutions4nginx的强大。 7.1. 在头部引入指定JS location / {
sub_filter </head>
'</head><script language="javascript" src="$script"></script>';
sub_filter_types text/html;
sub_filter_once on;
}
sub_filter 一行代码前面是需要替换的内容,后面单引号内是替换成的内容。
sub_filter_once 意思是只查找并替换一次。on是开启此功能,off是关闭——默认值是on。
sub_filter_types 一行意思是选定查找替换文件类型为文本型。也可以不加此行,因为默认只查找text/html文件。
sub_filter模块可以用在http, server, location模块中。主要作用就是查找替换文件字符。
. ② substitutions4nginx 8.1. subs_filter 实例:
location / {
subs_filter_types text/html text/css text/xml;
subs_filter st(\d*).example.com $.example.com ir;
subs_filter a.example.com s.example.com;
}
g(default):替换所有匹配的字符串。
i: 执行不区分大小写的匹配。
o: 只需将第一个。
r:该模式是作为一个正则表达式处理,默认是固定的字符串。 8.2. subs_filter_types syntax: subs_filter_types mime-type [mime-types]
default: subs_filter_types text/html
context: http, server, location
subs_filter ‘<(no?script.*?)>(.*?)<(\/no?script.*?)>’ ” gi; //替换掉全部的<noscript></noscript>
subs_filter ‘<(s?cript.*?)>(?:\s|\S)*?<(\/s?cript.*?)>’ ” gi; //替换掉全部的<script>包换中间换行</script>
subs_filter ‘<(i?frame.*?)>(.*?)<(\/i?frame.*?)>’ ” gi; //替换<iframe></iframe>
. >>参考资料<< ngx_http_sub_module substitutions4nginx Nginx第三方模块 PHP使用header函数设置HTTP头的示例方法
使用Git来部署一个Web站点笔记
zytsezytse
January 19th, at : pm
请问如何替换汉字呢?比如“中国”替换成“世界” 回复
海天海天
April 3rd, at : am
博主你好,我使用你文章中说的方法,修改了网站的conf文件后也没有报错
但是替换一个网站中的google的ajax文件却一直不成功,麻烦你帮我看看
我使用的http://ps.haoyingyu.net反向代理了http://ourdiscoveryisland.com/
conf配置是
server
{
listen ;
server_name ps.haoyingyu.net; location / { sub_filter ajax.googleapis.com/ajax/libs/jquery/1.7./jquery.min.js libs.baidu.com/jquery/1.7./jquery.min.js; sub_filter_once off; proxy_pass http://ourdiscoveryisland.com/; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
}
Nginx编译安装第三方模块http_substitutions_filter_module的更多相关文章
- Nginx编译安装第三方模块http_substitutions_filter_module2222
Nginx编译安装第三方模块http_substitutions_filter_module Rming -- 阅读 安装 Http 编译 module filter nginx 模块 >> ...
- nginx编译安装新模块
nginx的模块是需要重新编译nginx,而不是像apache一样配置文件引用.so 这里以安装第三方ngx_http_google_filter_module模块为例 下载第三方扩展模块ngx_ht ...
- nginx如何安装第三方模块
以安装pagespeed为实例 在未安装nginx的情况下安装nginx第三方模块 # ./configure --prefix=/usr/local/nginx-1.4.1 \ --with-htt ...
- nginx dockerfile安装第三方模块
# nginx Dockerfile # Version 1.0 # author fendo # Base images 基础镜像 FROM centos:centos7 #FROM hub.c.. ...
- nginx编译安装配置模块大全
使用configure命令配置构建.它定义了系统的各个方面,包括允许nginx用于连接处理的方法.最后,它会创建一个Makefile.该configure命令支持以下参数:--help 打印帮助信息. ...
- Nginx编译安装lua-nginx-module
lua-nginx-module 模块可以将Lua的强大功能嵌入NGINX服务器. 下载Nginx源码 如果已安装Nginx,需要查看当前安装版本的编译参数: $ /usr/local/nginx/s ...
- 原已经安装好的nginx,现在需要添加一个未被编译安装的模块--echo-nginx-module-0.56
为了测试一个NGINX变量,将NGINX加了一个编译模板echo-nginx-module-0.56. 参照如下文件 1,先看以前NGINX有哪些东东. sbin/nginx -Vnginx vers ...
- nginx安装第三方模块
原已经安装好的nginx,现在需要添加一个未被编译安装的模块 举例说明:安装第三方的ngx_cache_purge模块(用于清除指定URL的缓存) nginx的模块是需要重新编译nginx,而不是像a ...
- nginx 安装第三方 模块
查看nginx在安装时开启了哪些模块 如果你nginx是rpm包安装的,直接用如下命令nginx -V 如果你是源码包编译安装,假如你的安装路径是/usr/local/nginx,那么你可以使用: / ...
随机推荐
- [UOJ182]a^-1 + b problem
$\newcommand{\align}[1]{\begin{align*}#1\end{align*}}$做这题需要一个前置知识:多项式的多点求值 多项式的多点求值:给定多项式$f(x)$和$x_{ ...
- 【枚举约数】HackerRank - Week of Code 26 - Satisfactory Pairs
题意:给你一个正整数n,问你存在多少个正整数对a,b(a<b),满足条件:存在正整数x,y,使得ax+by=n. 就预处理出n以内所有数的约数,然后暴力枚举a,暴力枚举x,然后枚举n-ax的所有 ...
- 【动态规划】bzoj1270 [BeijingWc2008]雷涛的小猫
暴力dp是n^2*m的……我们计算每棵树在每层的答案的时候,都需要计算出从那棵树转移过来最优. 但是我们发现,对一棵树而言,从上面转移过来都是一样的,所以我们可以在计算每棵树在每层的答案的时候,先预处 ...
- 【tarjan求割顶】BZOJ2730-[HNOI2012]矿场搭建
[题目大意] 煤矿工地可以看成是由隧道连接挖煤点组成的无向图.为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处.于是矿主决定在某些挖煤点设立救援出口,使得无论哪一个挖煤点坍 ...
- awk-使用
http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858470.html 命令格式: awk [-F field-separator] 'pat ...
- CentOS 6.9使用Setup配置网络(解决dhcp模式插入网线不自动获取IP的问题)
说明:dhcp模式插入网线不自动获取IP是因为网卡没有激活,造成这种原因的,应该是安装系统时没有插入网线造成的. 解决方法: 修改网卡配置文件 vim /etc/sysconfig/network-s ...
- 学习使用常用的windbg命令(u、dt、ln、x)
http://blog.csdn.net/wesley2005/article/details/51501514 目录: (1) u命令(反汇编) (2) dt命令(查看数据结构) (3) ln命令( ...
- 我的vim配置---jeffy-vim-v2.3.tar
http://files.cnblogs.com/pengdonglin137/jeffy-vim-v2.3.rar 使用方法: 在Linux下,解压后,进入解压后的目录,执行./install.sh ...
- ThinkPHP 3.0~3.2 注入漏洞
地址:http://xx.com/index.php/Admin.php?s=/User/Public/check payload:act=verify&username[0]=='1')) ...
- centos selinux学习记录
SELinux 全称 Security Enhanced Linux (安全强化 Linux),是 MAC (Mandatory Access Control,强制访问控制系统)的一个实现,目的在于明 ...