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)

}

相关推荐
C_心欲无痕1 天前
nginx - alias 和 root 的区别详解
运维·前端·nginx
徐同保1 天前
nginx转发,指向一个可以正常访问的网站
linux·服务器·nginx
C_心欲无痕1 天前
nginx - 开启 gzip 压缩
运维·前端·nginx
C_心欲无痕1 天前
nginx - 核心概念
运维·前端·nginx
洋葱 ☠2 天前
极简部署linux免费ssl证书Let‘s Encrypt,自动续签,nginx/apache都可以,域名指向服务器即可,无需项目
linux·nginx·ssl
shenghuiping20012 天前
OPSWAT https enable 问题解决
nginx·https·ssl·443·opswat
oMcLin2 天前
如何在Ubuntu 22.04上通过调优Nginx和PHP‑FPM,提升高并发WordPress网站的负载均衡与缓存性能?
nginx·ubuntu·php
气概2 天前
法奥机器人学习使用
学习·junit·机器人
五仁火烧2 天前
Vue3 项目的默认端口行为
服务器·vue.js·nginx·容器·vue
oMcLin2 天前
如何在 RHEL 7 上优化 Nginx 与 PHP‑FPM 配置,确保高并发 Web 应用的稳定性与响应速度?
前端·nginx·php