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)

}

相关推荐
猫头虎5 小时前
web开发常见问题解决方案大全:502/503 Bad Gateway/Connection reset/504 timed out/400 Bad Request/401 Unauthorized
运维·前端·nginx·http·https·gateway·openresty
金銀銅鐵12 小时前
浅解 Junit 4 第七篇:AllDefaultPossibilitiesBuilder
java·junit·单元测试
金銀銅鐵1 天前
浅解 Junit 4 第六篇:AnnotatedBuilder 和 RunnerBuilder
后端·junit·单元测试
Trouvaille ~2 天前
【Linux】网络进阶:NAT技术与代理服务器详解
linux·运维·网络·nginx·ip·nat·代理服务器
金銀銅鐵2 天前
浅解 Junit 4 第五篇:IgnoredBuilder 和 RunnerBuilder
junit·单元测试
白太岁2 天前
Redis:(3) Lua 与 Redis、基于连接池的 Facade 模式封装
数据库·c++·redis·lua·外观模式
之歆3 天前
Nginx + Tomcat 反向代理完全指南
nginx·tomcat·firefox
匀泪3 天前
云原生(nginx实验(4))
运维·nginx·云原生
FJW0208143 天前
《Nginx 进阶实战:配置详解、站点发布与常用功能大全》(2)
运维·nginx
问道飞鱼3 天前
【服务器知识】nginx配置负载均衡完全解读
服务器·nginx·负载均衡