Nginx 反向代理内容替换(整理总结一套自己需要的东西)

1.修改 nginx 的./configure 模块,

添加反向代理和动态内容替换

#su

(先进入 root 状态)

# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --add-module=/data/software/ngx_http_substitutions_filter_module --add-module=/data/software/ngx_http_google_filter_module

#make

注意:1.这里不能按 make install 2.必须进入 root 状态,否则编译过程中会出现--prefix=**的时候 permisson deny。

2.进入 nginx.conf 文件进行修改内容。

      location / {

                 proxy_pass http://127.0.0.1:8080;

                 proxy_redirect off; subs_filter   ‘原内容‘   ‘替换成的内容’;

                 Index index.html index.htm;
                 sub_filter_once on;
}
3.一些常用语法:

sub_filter 指令: sub_filter string(原字符串) replacement(用于替换的字符串); 用于设置需要使用说明字符串替换说明字符串.string 是要被替换的字符串,replacement 是 新的字符串,它里面可以带变量。


sub_filter_last_modified 指令: sub_filter_last_modified on | off;

用于设置网页内替换后是否修改 可在 nginx.conf 的 http, server, location 三个位置配 置使 用,默认值是 off;


sub_filter_once 指令:sub_filter_once on | off;

用于设置字符串替换次数,默认只替换一次。如果是 on,默认只替换第一次匹配到的到字 符,如果是 off,那么所有匹配到的字符都会被替换;


sub_filter_types 指令:sub_filter_types *

用于指定需要被替换的 MIME 类型,默认为“text/html”,如果制定为*,那么所有的;


说明:以上指令可在 nginx.conf 的 http, server, location 三个位置配置使用;
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值