/etc/nginx/sites-enabled/example.com.conf
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.html;
# Using Nginx's ngx_http_sub_module module to modify the request content
# Ref. http://nginx.org/en/docs/http/ngx_http_sub_module.html
# Inject an HTML element
sub_filter '<body>' '<body><br/><h1>Hello! this is an injected content 💉</h1>';
# Inject a script that will show an alert on window click
sub_filter '</head>' '<script language="javascript">window.onclick=function(){alert("Hello from injected script!")}</script></head>';
sub_filter_once on;
}
sub_filter
will replace the text with another text.sub_filter_once on;
set toon
to only replace the first occurence.