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)

}

相关推荐
zz0723204 小时前
Lua 脚本
lua·脚本语言·redis+lua
Dxy123931021615 小时前
为什么开了 `open_file_cache` 图片会不显示?
nginx
念何架构之路17 小时前
接入LVS+Nginx和服务发现
nginx·服务发现·lvs
ThinkPet1 天前
记事-vue3项目部署Jenkins实现CICD流程
运维·nginx·jenkins·jenkinsfile·cicd流水线
零壹AI实验室1 天前
AI发现潜伏18年的NGINX高危漏洞:CVE-2026-42945完整技术分析
运维·人工智能·nginx
锋行天下2 天前
让nginx网关扛下所有攻击
前端·后端·nginx
代码熬夜敲Q2 天前
Nginx相关
运维·服务器·nginx
念何架构之路2 天前
接入层Nginx
运维·nginx
wapicn992 天前
API接口调试笔记:从注册到第一个数据返回,全流程详解
java·开发语言·python·lua