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)

}

相关推荐
盟道科技5 小时前
Redis+Lua 实现滑动窗口限流:从固定窗口踩坑到生产可用的完整方案
redis·junit·lua
Rain的Java大神之路18 小时前
JavaWeb开发如何解决跨域问题
java·前端·后端·nginx·web安全·面试·运维开发
Lsetea1 天前
Nginx报SSL_CTX_use_PrivateKey failed:证书与私钥不匹配怎么排查
nginx·https·ssl证书·openssl·私钥
!chen1 天前
客户环境 Nginx 配置流式报表与超时排查
运维·nginx
大喵桑丶1 天前
AlmaLinux 9 上基于 PostgreSQL + Nginx 部署高可用轻量级 Gitea 服务
nginx·postgresql·gitea
我最爱吃鱼香茄子2 天前
【踩坑实录】若依Vue宝塔部署:验证码空白、反复提示登录状态已过期|完整排错
nginx·宝塔·若依·ruoyi‑vue·登录状态已过期
dazhong20122 天前
Docker 进阶篇(二) Docker Compose 部署 Nginx 实践
nginx·docker·容器
笑梦无境2 天前
nginx安装(5)
linux·运维·nginx
墨着染霜华3 天前
SpringCloud Gateway线上Nginx代理后自定义下划线请求头丢失(app_name/app_version获取不到)完美解决
nginx·spring cloud·gateway
流光D3 天前
AI Era: Building Web Sites and Configuring Nginx Reverse Proxy Process
前端·人工智能·nginx