Thanks for the advice!
For some reason I now only get empty page in response even with replace_filter marked out.
However adding ngx.say("Something") at the bottom of the script does return Something in response...
It seems I'm touching something I don't suppose to. Do I?
Now the .conf portion looks like this:
location / {
resolver 8.8.8.8;
root html;
index index.html index.htm;
content_by_lua_file '/home/cxadmin/Work/filter.lua';
replace_filter '</head>' 'ngx.ctx.replaceScript' ig;
}