sub_filter
和 subs_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
(完)