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)

}

相关推荐
吹晚风吧34 分钟前
解决vite打包,base配置前缀,nginx的dist包找不到资源
服务器·前端·nginx
chxii4 小时前
Nginx 正则 location 指令匹配客户端请求的 URI
前端·nginx
難釋懷5 小时前
OpenResty封装Redis工具
redis·junit·openresty
静心观复5 小时前
Lua 脚本是什么
开发语言·lua
LcGero5 小时前
Lua 协程(Coroutine):游戏里的“伪多线程”利器
游戏·lua·游戏开发·协程
橙露5 小时前
Nginx 反向代理与负载均衡:配置详解与高可用方案
运维·nginx·负载均衡
星夜泊客6 小时前
《Lua 模块化核心:require 的地址传递与缓存机制》
缓存·lua
ling__i7 小时前
接口测试常见问题
开发语言·lua
gfdhy7 小时前
【Linux服务器】基础服务实战部署|Nginx+MySQL+PHP+WordPress,让服务器真正可用
linux·服务器·mysql·nginx·php·毕设
LcGero16 小时前
Lua 进阶:元表(Metatable)如何实现“类系统”?
lua·元表