首页 » 操作系统 » Linux » 正文

nginx 反向代理时修改网站内容后再显示

发布者:站点默认
2015/04/23 浏览数(2,358) 分类:Linux, Nginx nginx 反向代理时修改网站内容后再显示已关闭评论

效果:

nginx_proxy_thief

命令

service nginx stop
cd
git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git
或
yum install subversion
svn checkout http://substitutions4nginx.googlecode.com/svn/trunk/ substitutions4nginx-read-only
wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar -zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --add-module=/root/substitutions4nginx-read-only
make
make install
cp /usr/sbin/nginx ~/webSvrBak/nginx.bak
cp objs/nginx /usr/sbin/nginx

vi /etc/nginx/conf.d/oa.****h.com.conf
server {
   listen       80;
   server_name  oa.****h.com;
   location / {
      proxy_pass http://www.cl****ebsoft.com/;
      proxy_redirect default;
      subs_filter 'www.****home.com' 'oa.****h.com';
      subs_filter 400-619-**** 03**-**620000;
      subs_filter '苏ICP备****2525' '豫ICP备****5058号';
      subs_filter '南京****软件技术有限公司' '洛阳****信息技术有限公司';
      subs_filter '/images/weixin.gif' 'http://www.****.com/qrCodeWechat.gif';
      subs_filter_types text/html;
   }
}

service nginx start

subs_filter_types

语法: subs_filter_types mime-type [mime-types]

默认:subs_filter_types text/html

适用区域:http, server, location

subs_filter_types是用来指令需要替换的文件类型,默认是text/html类型。此模块无法处理经过压缩的内容,虽然能与gzip filter模块兼容,但无法处理反向代理返回的内容。当需要处理反向代理的内容时,可以使用如下语句禁用压缩:

proxy_set_header Accept-Encoding “”;

subs_filter

语法:subs_filter 源字段串 目标字段串 [gior]

默认:无

适用区域:http, server, location

subs_filter指令允许在nginx响应输出内容时替换源字段串(正则或固定)为目标字符串。第三个标志含意如下:

g: 替换所有匹配的字段串(默认)。

i: 执行区分大小写的匹配。

o: 仅替换首个匹配字符串。

r: 使用正则替换模式,默认是固定模式。
— 完 —

点击返回顶部
  1. 留言
  2. 联系方式