How to inject custom content via Nginx?

筅森魡賤 提交于 2020-07-16 16:51:50

问题


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?

I know, you should be able to use lua in nginx but is there a better solution?

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.


回答1:


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;
}


来源:https://stackoverflow.com/questions/19700871/how-to-inject-custom-content-via-nginx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!