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.arg1: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.arg1 = ngx.arg1:gsub("</head>", script)

}

相关推荐
打工仔折腾 AI11 小时前
FastAPI 从本机到生产服务器:Nginx+Gunicorn+Uvicorn 完整部署实录
人工智能·后端·python·nginx·fastapi·gunicorn
Linux运维技术栈16 小时前
如何避免绕过CDN的攻击?基于 CDN 回源请求头鉴权的防御实操与安全性剖析
nginx·安全·cdn
Lsetea20 小时前
OpenSSL快速生成域名证书:含SAN的自签命令、验证与排错
nginx·https·ssl证书·openssl·自签证书
小小的木头人2 天前
CentOS 7 下 Nginx 访问自定义目录报 403 的完整排查:从端口权限到 SELinux
nginx·centos
新时代农民工~2 天前
【双机高可用部署方案-前后端部署】
java·nginx·springboot
运维全栈笔记2 天前
Nginx 模块化多业务站点通用配置模板
linux·运维·nginx
蓝胖的四次元口袋3 天前
Docker Compose多容器编排与Nginx集群实战
运维·nginx·docker compose
师傅别念了3 天前
Nginx 反向代理配置指南,看完这篇就够了
nginx
bst@微胖子3 天前
Linux环境做LVM快照
lua
迷茫的大专生4 天前
高可用总结
redis·mysql·nginx·高可用