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)

}

相关推荐
痕迹运维1 小时前
Nginx SFTP代理
nginx
BreezeJiang2 小时前
为什么生成了 dist,项目还是可能跑不起来?从一个 React + Express + MySQL 项目看部署闭环
nginx·react.js
Darling噜啦啦2 小时前
前端到上线全流程:从买服务器到 Nginx 反向代理,搞懂全栈部署
nginx·全栈
烬羽2 小时前
我把"时间胶囊"部署上腾讯云宝塔,跨域从根源消失了
nginx·node.js·全栈
呆呆敲代码的小Y1 天前
【游戏开发】Lua 与 C# 交互原理解析
c#·lua·交互·热更新·lua与c#交互·游戏热更新
呆呆敲代码的小Y1 天前
Lua 上值(UpValue)
开发语言·junit·lua·lua上值·upvalue
呆呆敲代码的小Y1 天前
【游戏开发】xLua 性能优化技巧
junit·性能优化·lua·xlua
曼巴UE51 天前
Unlua UE5.3 调试
ue5·lua·unlua
nvd111 天前
实战:用 Lua 手写 Kong 安全鉴权插件并通过 ArgoCD GitOps 零编译部署到 DbGate 服务
安全·lua·kong
En^_^Joy1 天前
Nginx 从入门到精通:配置、原理与实战详解
运维·nginx