ngx_http_addition_module
Add text before and after a response body via subrequests
Overview
ngx_http_addition_module is a filter that adds text before and after a response. The text is not a literal string: each directive names a URI, nginx runs a subrequest for it, and the body of that subrequest is prepended or appended to the main response.
By default only text/html responses are touched. addition_types (0.7.9) widens this to other MIME types, and the special value "*" matches any MIME type (0.8.29). Passing an empty string ("") to add_before_body or add_after_body cancels an addition inherited from a previous configuration level.
It is an official nginx module. Upstream does not build it by default and enables it with the --with-http_addition_module configure parameter. A typical use is wrapping static HTML pages in a shared header and footer served from another location or an upstream.
Key directives
add_before_bodyAdds the text returned by a subrequest to the given URI before the response body; http, server, location.add_after_bodyAdds the text returned by a subrequest to the given URI after the response body; http, server, location.addition_typesMIME types that may receive additions besides text/html, "*" matches any type; default text/html.cancel with ""An empty string as the parameter cancels an addition inherited from the previous configuration level.Example
Availability
Compiled into every n.wtf nginx binary. Install nginx-extras and the directives above work out of the box, no load_module line needed.