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)

}

相关推荐
Meepo_haha2 小时前
Nginx 反向代理配置
运维·nginx
上海合宙LuatOS2 小时前
LuatOS扩展库API——【airlbs 】airlbs 定位服务
物联网·lua·嵌入式实时数据库·airlbs定位服务
星辰徐哥4 小时前
C语言Web开发:CGI、FastCGI、Nginx深度解析
c语言·前端·nginx
上海合宙LuatOS4 小时前
LuatOS扩展库API——【dhcpsrv】DHCP服务器
物联网·开源·lua·luatos
sunwenjian8865 小时前
httpslocalhostindex 配置的nginx,一刷新就报404了
运维·nginx
luanma1509805 小时前
PHP vs Lua:脚本语言核心差异解析
开发语言·php·lua
bearpping5 小时前
nginx 代理 redis
运维·redis·nginx
ywf12156 小时前
Nginx 缓存清理
运维·nginx·缓存
dustcell.6 小时前
企业级高可用电商平台实战项目设计
运维·redis·nginx·docker·web·lvs·haproxy
chehaoman17 小时前
Failed to restart nginx.service Unit nginx.service not found
运维·nginx