lua脚本动态插入script标签 在nginx层面

body_filter_by_lua_block{

local pin = ngx.var.cookie_jrapp_jsfGateway_testPin

local domain = ngx.var.host

local scheme = ngx.var.scheme

local title = "白条"

local match = ngx.arg[1]:match("<title>([^<]+)</title>")

if match then

title = match

end

if not pin then

pin = "未知pin"

end

local script = string.format('<script crossorigin=\"anonymous\" src=\"%s://%s/page-spy/index.min.js\"></script><script>window.$pageSpy=new PageSpy({ project: \"%s\", title: \"%s\" })</script></head>', scheme,domain,title, pin)

ngx.arg[1] = ngx.arg[1]:gsub("</head>", script)

}

相关推荐
DuelCode17 小时前
Windows VMWare Centos Docker部署Springboot 应用实现文件上传返回文件http链接
java·spring boot·mysql·nginx·docker·centos·mybatis
dyj0951 天前
【Rancher Server + Kubernets】- Nginx-ingress日志持久化至宿主机
运维·nginx·rancher
PanZonghui1 天前
Centos项目部署之Nginx部署项目
linux·nginx
Hellc0071 天前
Nginx 高级 CC 与 DDoS 防御策略指南
运维·nginx·ddos
小皮侠1 天前
nginx的使用
java·运维·服务器·前端·git·nginx·github
梁bk1 天前
[Nginx]反向代理和负载均衡
运维·nginx·负载均衡
绝不偷吃2 天前
FastDFS分布式储存
linux·nginx
java1234_小锋2 天前
解释一下NGINX的反向代理和正向代理的区别?
运维·nginx
PanZonghui2 天前
Centos项目部署之Nginx 的安装与卸载
linux·nginx
charlee443 天前
nginx部署发布Vite项目
nginx·性能优化·https·部署·vite