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)

}

相关推荐
tzy23313 小时前
Nginx 的重定向规则
nginx·location·return·302·301·rewrite·last
胡利光14 小时前
Harness Engineering 05|Safety & HITL Harness:边界、接管与回滚
junit
明月_清风16 小时前
Nginx 模块机制深度解析:从核心原理到生产实践
前端·nginx
liulilittle19 小时前
递归复制搜索所有的lua文件到指定目录
java·开发语言·lua·cmd
明月_清风20 小时前
Nginx 生产环境配置完全指南:从安全加固到性能调优
前端·nginx
zzzb12345621 小时前
WSL(Ubuntu)部署Nginx\+PHP8\.2完整教程(新手友好\+避坑指南)
linux·nginx·ubuntu·php
上海合宙LuatOS1 天前
LuatOS扩展库API——【xmodem】文件传输协议
物联网·junit·luatos
加号31 天前
Nginx 实现负载均衡:从原理到实践的完整指南
运维·nginx·负载均衡
上海合宙LuatOS1 天前
LuatOS 课程-011 讲:GNSS应用开发
网络·物联网·lua·luatos
LcGero2 天前
游戏引擎Luanti的前世今生与技术解析
游戏引擎·lua·游戏开发·我的世界·luanti