Changing content on-the-fly
Sometimes, it may be helpful to postprocess what comes from your application. Maybe you would like to add a string at a certain point in your page to show which frontend server delivered that page to the client. Or maybe you would like to perform a transformation on the rendered HTML page. NGINX provides three modules that could be useful here: the addition module, the sub module, and the xslt module.
Using the addition module
The addition module works as a filter to add text before and/or after a response. It is not compiled by default, so if you want to make use of this feature, you must enable it at configure time by adding --with-http_addition_module.
This filter works by referencing a subrequest, which is then either appended to a request, or placed at the beginning of one:
server {
root /home/www;
location / {
add_before_body /header;
add_after_body /footer;
}
location /header {
proxy_pass http://127.0.0.1:8080/header;
}
location...