Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inject custom content via Nginx?

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.

like image 516
pasuna Avatar asked Oct 31 '13 07:10

pasuna


1 Answers

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; } 
like image 92
pasuna Avatar answered Sep 29 '22 20:09

pasuna