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)

}

相关推荐
geekmice2 小时前
thymeleaf处理参数传递问题
开发语言·lua
通明湖2 小时前
如何从Ingress NGINX无缝迁移到OpenNJet KIC
nginx
大大大水蜜桃3 小时前
Nginx HTTPS服务搭建实验
运维·nginx·https
BugShare3 小时前
粗心大意必酿大祸,记录nginx配置文件的一次闹剧
运维·nginx
岁岁种桃花儿5 小时前
一文了解什么是http dns对比传统dns有哪些优势?
nginx·dns
geekmice8 小时前
Thymeleaf传递复杂对象参数解决思路
开发语言·lua
徐同保8 小时前
Nginx不能转发带有websocket功能的项目解决方案
运维·websocket·nginx
Swizard8 小时前
Nginx 反向代理实战指南:从动态解析到 WebSocket
websocket·nginx·反代
007php0079 小时前
redis缓存功能结合实际项目面试之问题与解析
网络·redis·nginx·缓存·面试·职场和发展·php
岁岁种桃花儿9 小时前
一文了解什么是短网址以及他的做用是什么
网络·nginx·dns·短网址