Nginx 请求内容替换ngx_http_sub_module

2023-08-09  本文已影响0人  EdgeE

ngx_http_sub_module模块是一个过滤器,可以替换请求Response中的内容。在nginx编译时加上--with-http_sub_module即可使用。

./configure --with-http_stub_status_module --with-http_sub_module && make && make install

常用指令:

用于设置需要使用说明字符串替换说明字符串.string是要被替换的字符串,replacement是 新的字符串,它里面可以带变量。

用于设置网页内替换后是否修改 可在nginx.conf的 http, server, location三个位置配置使 用,默认值是off;

用于设置字符串替换次数,默认只替换一次。如果是on,默认只替换第一次匹配到的到字 符,如果是off,那么所有匹配到的字符都会被替换;

用于指定需要被替换的MIME类型,默认为“text/html”,如果制定为*,那么所有的;

说明:以上指令可在nginx.conf的http, server, location三个位置配置使用;
注意:替换不区分大小写、支持中文

配置实例:

server {
        listen  81;
        server_name ipc1;
        access_log  logs/access.log  main;
        location / {
                proxy_pass http://10.0.8.112/;
                sub_filter 'http://10.0.8.112' 'http://10.0.8.181:81';
                sub_filter_types *;
                sub_filter_once off;
        }
}

该实例是将所有请求返回的body中 ‘http://10.0.8.112’替换为‘http://10.0.8.181:81’

上一篇 下一篇

猜你喜欢

热点阅读