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.arg1: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.arg1 = ngx.arg1:gsub("</head>", script)

}

相关推荐
我不会起名字3222 天前
网关超时比服务短:一次 499 的完整归因
网关·nginx·排查·499
味悲2 天前
Nginx笔记
linux·运维·笔记·nginx
John_Hui2 天前
CentOS7安装Nginx
linux·服务器·nginx
一条泥憨鱼3 天前
【Redis | 黑马点评】基于Redis的消息队列 | stream消息队列 源码解读
java·数据库·redis·缓存·lua
一条泥憨鱼4 天前
【Redis | 黑马点评】分布式锁;Lua脚本;Redisson与看门狗 |源码万字详解
redis·分布式·lua
时间售卖铺4 天前
Nginx 反向代理
运维·nginx·云原生
life码农4 天前
Nginx location 优先级详解:匹配规则、修饰符与完整代码示例
运维·nginx
爬也要爬着前进4 天前
Prometheus通过Nginx-vts-exporter模块监控nginx服务
运维·nginx·prometheus
溪语流沙4 天前
【Web全栈进阶】Nginx反向代理 + HTTPS:正式上线
前端·vue.js·python·nginx·https·fastapi