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)

}

相关推荐
傻瓜搬砖人19 小时前
SpringBoot整合Junit-Redis-打包
spring boot·redis·junit
Arya_aa1 天前
四:部署前端和后端
nginx
晴夏。1 天前
unlua实现原理
游戏·ue5·ue4·lua·ue·unlua
Java面试题总结1 天前
一文搞定 Linux Nginx 从安装、启动到 nginx.conf 全配置详解(新手也能看懂)
linux·运维·nginx
晴夏。1 天前
c++调用lua的方法
c++·游戏引擎·lua·ue
MiNG MENS2 天前
nginx 代理 redis
运维·redis·nginx
珊瑚怪人2 天前
一个域名问题
nginx
dxdz2 天前
一文搞定 Linux Nginx 从安装、启动到 nginx.conf 全配置详解(新手也能看懂)
nginx
chxii2 天前
lua中Table 与 Metatable
lua
遇见火星2 天前
Nginx 负载均衡配置模板:轮询、权重、IP哈希、最少连接
tcp/ip·nginx·负载均衡