sub_filtersubs_filter 区别

  • sub_filter( 0.7.24):替换响应体(Response Body)中的文本,只能设置一组替换。
  • subs_filter:替换响应体(Response Body)和响应头(Response Headers)中的文本,能够设置多组替换。

sub_filter 应用案例:

http {    server {        listen 80;        server_name example.com;        location / {            sub_filter 'old-text' 'new-text';            sub_filter_once off;            proxy_pass http://backend;        }    }}

subs_filter 应用案例:

http {    server {        listen 80;        server_name example.com;        location / {            subs_filter 'old-text-1' 'new-text-1';            subs_filter 'old-text-2' 'new-text-2';            proxy_pass http://backend;        }        subs_filter_types text/*;        subs_filter_types application/json;    }}

装置形式

办法 1:命令行装置

CentOS 惯例装置的 Nginx 中并不蕴含 subs_filter,须要额定装置 nginx-mod-http-sub 增加对其性能的反对。

1. 装置模块

sudo dnf install nginx-mod-http-sub

2. 加载模块

load_module modules/ngx_http_subs_filter_module.so;

CentOS 零碎下只有 Nginx Plus 能力这么操作,否则须要从新编译 Nginx。Debian 零碎曾经间接装置了此模块。

办法 2:源码编译

1. 下载模块

git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git

2. 编译

./configure --add-module=/path/to/module

版权申明

本博客所有的原创文章,作者皆保留版权。转载必须蕴含本申明,放弃本文残缺,并以超链接模式注明作者后除和本文原始地址:https://blog.mazey.net/3525.html

(完)