CentOS 9 安装 Nginx 模块 `subs_filter`
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
(完)
GitHub: https://github.com/mazeyqian
Blog: https://blog.mazey.net/
Blog: https://blog.mazey.net/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2022-05-28 npm/cnpm 设置镜像地址