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)

}

相关推荐
绝不偷吃6 小时前
FastDFS分布式储存
linux·nginx
java1234_小锋8 小时前
解释一下NGINX的反向代理和正向代理的区别?
运维·nginx
PanZonghui16 小时前
Centos项目部署之Nginx 的安装与卸载
linux·nginx
charlee441 天前
nginx部署发布Vite项目
nginx·性能优化·https·部署·vite
CRMEB定制开发1 天前
【实战】CRMEB Pro 企业版安装教程(附 Nginx 反向代理配置 + 常见问题解决)
nginx·商城系统·微信商城·crmeb
孙克旭_2 天前
day045-nginx跳转功能补充与https
linux·运维·nginx·https
博同学2 天前
Nginx + ELK + Grafana 全球访问热力图
nginx·elk·grafana
RW~2 天前
Minio安装配置,桶权限设置,nginx代理 https minio
运维·nginx·https·minio
旷世奇才李先生2 天前
Lua 安装使用教程
开发语言·lua
CodeWithMe2 天前
Nginx入门进阶:从零到高手的实战指南
运维·nginx