nginx的http_sub_module模块使用之替换字符串

Nginx可以实现很多功能,提供了许多插件,其中一个比较冷门的http_sub_module,是用来替换指定字符串的,它的原理是Nginx解析到文件后,执行这个插件进行拦截后返回。

昨天碰到一个场景,之前外包提供的只有一个jar包,反编译后各种错,但是有一个配置是写死在jar包里面的,替换无效,后来请教了大佬之后原来Nginx还有这个插件,摸索了一下。希望可以帮助到有需要的朋友。

location / {
           sub_filter 'nginx.com' 'baidu.com'; --把nginx.com替换成了baidu.com
           sub_filter 'nginx.org' 'buy.jiegeng.com';--把ngin.org替换成了buy.jiegeng.com
           sub_filter_types css/html;--替换的类型
           sub_filter_once off;--全部替换
           root  html;
           index  index.html index.htm;
        }

猜你喜欢

转载自www.cnblogs.com/azhqiang/p/9927401.html