如何通过Nginx注入自定义内容? [英] How to inject custom content via Nginx?
问题描述
是否有一种方法为每一个php / html / etc注入几行脚本等。页?
例如,在-tag之后添加一些自定义javascript?
Is there a way to inject a few lines of script etc. for each served php/html/etc. page? For example some custom javascript after -tag?
我知道,您应该可以在nginx中使用lua,但是有更好的解决方案吗?
I know, you should be able to use lua in nginx but is there a better solution?
我正在nginx后面运行多个不同的Web应用程序,因此感觉这样做很合适。我没有每个应用程序的访问源代码,维护这些代码很麻烦。
I am running multiple different web application behind the nginx, so it feels proper way to do this. I don't have access source code for each application and maintaining those would be cumbersome.
推荐答案
我找到了实现此目的的方法: http://nginx.org/en/docs/http/ngx_http_sub_module.html
I found the way to do this: http://nginx.org/en/docs/http/ngx_http_sub_module.html
location / {
sub_filter </head>
'</head><script language="javascript" src="$script"></script>';
sub_filter_once on;
}
这篇关于如何通过Nginx注入自定义内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!