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)

}

相关推荐
打工的小王10 小时前
nginx(一)nginx简介
nginx
李少兄13 小时前
深入解析 Nginx 413 Request Entity Too Large 错误
运维·nginx
想做后端的前端16 小时前
Redis中的Lua使用
数据库·redis·lua
weixin_3954489116 小时前
draw_tensor2psd.py_cursor
lua·perl·symfony
漏刻有时16 小时前
宝塔服务器被篡改 Nginx Location 配置的安全风险剖析与修复指南(流量劫持、服务器资源消耗、站点功能异常、溯源困难)
服务器·nginx·安全
你知道“铁甲小宝”吗丶16 小时前
nginx代理ip哈希用法
nginx·哈希算法
预立科技1 天前
Redis 中 Lua 与 Pipeline 的相同点,区别,使用场景
redis·pipeline·lua
代码的奴隶(艾伦·耶格尔)1 天前
Nginx
java·服务器·nginx
液态不合群1 天前
Nginx多服务静态资源路径冲突解决方案
运维·nginx
岁岁种桃花儿1 天前
详解kubectl get replicaset命令及与kubectl get pods的核心区别
运维·nginx·容器·kubernetes·k8s