可以使用ngx_http_sub_module模块进行html代码替换,例如下面就是在返回的html页面注入插入了一段js代码
location / {还可以按照标签进行替换;
sub_filter <head>
'<head><script>window[\'adrum-start-time\'] = new Date().getTime();</script><script src="/adrum.js"></script>';
sub_filter_once on;
}
location / {
sub_filter '<a href="http://127.0.0.1:8080/' '<a href="https://$host/';
sub_filter '<img src="http://127.0.0.1:8080/' '<img src="https://$host/';
sub_filter_once on;
}
网友回复