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)

}

相关推荐
连续讨伐1 小时前
前期小随笔
服务器·网络·nginx
s_daqing1 天前
ubuntu(arm)使用nginx安装静态服务器
服务器·nginx·ubuntu
物有本木1 天前
httpsok-v2.0.8发布-支持IIS证书自动续签
nginx·ssl
Volunteer Technology1 天前
Nginx部署静态项目
运维·服务器·nginx
摇滚侠1 天前
尚硅谷 Nginx 教程(亿级流量 Nginx 架构设计),基本使用,笔记 6-42
java·笔记·nginx
衫水1 天前
Ubuntu 系统部署 Vue/Vite 应用到 Nginx
vue.js·nginx·ubuntu
资料库011 天前
LVS、Nginx、HAProxy核心区别是什么?
运维·nginx·lvs
移幻漂流1 天前
Lua的现状与机遇:技术生态全景及高潜力领域分析
junit·单元测试·lua
我发在否1 天前
OpenResty > Lua断点调试
vscode·lua·断点·openresty·luapanda
Filotimo_2 天前
Nginx 的概念
运维·nginx