nginxcurl html body,nginx 替换网站响应内容(ngx_http_sub_module)

nginx在编译安装的时候需要编译安装这个模块--with-http_sub_module

make && make install

语法:     sub_filter old_string new_string;

默认值:     —

配置段:     http, server, location

这三个段都可以配置sub_filter

设置需要使用说明字符串替换说明字符串.old_string是要被替换的字符串,new_string是新的字符串,它里面可以带变量。

语法:       sub_filter_last_modified on | off;

默认值:     sub_filter_last_modified off;

配置段:      http, server, location

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

语法: sub_filter_once on | off;

默认值: sub_filter_once on;

配置段: http, server, location

字符串替换一次还是多次替换,默认为on只替换一次,如果off,那么所有的old_string都会被替换

语法: sub_filter_types mime-type ...;

默认值: sub_filter_types text/html;

配置段: http, server, location

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

例子:

在nignx上加上个server,在localtion上加server {

listen       80;

server_name  www.hxy.com;

root /data/www;

location / {

sub_filter  world 'hxy';

}

}cat /data/www/index.html

hello world

curl

hello hxy

在localhost上加入生效了,现在在server上加入:server {

listen       80;

server_name  www.hxy.com;

sub_filter  world 'hxy123';

root /data/www;

}cat /data/www/index.html

hello world

curl www.hxy.com

hello hxy123

server上也生效了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值