文章

nginx_ngx_replace_filter模块

replace_filter模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
https://github.com/openresty/replace-filter-nginx-module
功能:响应正文中的流式正则表达式替换
模块: replace-filter-nginx-module
指令: replace_filter <regex> <replace>
      replace_filter <regex> <replace> <options>
      
      options:
        g: 全局搜索和替换(默认关闭该功能)
        i: 不区分大小写(默认关闭)
默认: no
可以出现在: http, server, location, location if

例子: 全局搜索 把 img.test.com 替换为: media.test.com 
location ~ [^/]\.php(/|$)
{
  replace_filter 'img.test.com' 'media.test.com' g;
  replace_filter_types application/json;
  
  # comment try_files $uri =404; to enable pathinfo
  try_files $uri =404;
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  include fastcgi.conf;
}
本文由作者按照 CC BY 4.0 进行授权