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)

}

相关推荐
ZHOU西口8 小时前
微服务实战系列之玩转Docker(十五)
nginx·docker·微服务·云原生·swarm·docker swarm·dockerui
苹果醋312 小时前
react 路由 react-router/react-router-dom
运维·nginx
Lill_bin16 小时前
Lua编程语言简介与应用
开发语言·数据库·缓存·设计模式·性能优化·lua
ps酷教程20 小时前
nginx进阶篇(二)
nginx
双普拉斯20 小时前
微信小程序点赞动画特效实现
nginx·微信小程序·notepad++
苏少朋20 小时前
Docker安装 ▎Docker详细讲解 ▎数据卷挂载 ▎Nginx安装理解
linux·nginx·docker·容器
比花花解语20 小时前
怎么使用nginx把80端口代理到想要的端口?
运维·nginx
两水先木示21 小时前
【Lua坑】Lua协程coroutine无法正常完整执行问题
开发语言·lua·协程·对象池
工程师老罗1 天前
Java笔试面试题AI答之单元测试JUnit(6)
java·junit·单元测试
ps酷教程1 天前
nginx基础篇(一)
nginx