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)

}

相关推荐
逻各斯9 小时前
redis中的Lua脚本,redis的事务机制
java·redis·lua
fajianchen17 小时前
什么是HTTP/2协议?NGINX如何支持HTTP/2并提升网站性能?
nginx·http
m0_7482487719 小时前
在 Ubuntu 上安装 Nginx 的详细指南
nginx·ubuntu·postgresql
煤炭里de黑猫1 天前
Lua C API :使用 lua_tonumber 函数从 Lua 栈中提取数值
开发语言·lua
若云止水1 天前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_os_init 函数
运维·nginx
m0_512744641 天前
Nginx(详解以及如何使用)
运维·服务器·nginx
煤炭里de黑猫1 天前
Lua C API:深入理解 lua_pushnumber 函数 — 将数字压入 Lua 栈中
开发语言·lua
铁锅与大鹅2 天前
http+nginx
网络协议·nginx·http
2501_903238652 天前
深入理解 JUnit 的 @RunWith 注解与自定义 Runner
数据库·junit·sqlserver·个人开发
煤炭里de黑猫2 天前
Lua C API :lua_insert 函数详解
开发语言·lua