nginx filter to concat text to a response body

Filipe Silva fs20063 at outlook.com
Sat Sep 22 05:28:50 UTC 2012


Hi Zhu,
I tried taobao's module and it works like a charm if nginx is configured as a web server:
server {
	listen       80;
	server_name  localhost;

	location / {
	    footer "<!-- $date_gmt -->";
	    index index.html;
	}
}
The result is a html comment with a gmt date like <!-- 1234567890 --> added to the end of the response body.
But if configured like a reverse proxy it does not add the comment.
server {	listen       80;	server_name  localhost;
	location / {            proxy_pass         http://127.0.0.1:8080/;
	    footer "<!-- $date_gmt -->";	}}
Well, this simple nginx location configuration points the traffic to a upstream web server. As expected, on return I don't get the nginx's default index.html, but the upstream html page instead, with the difference that the comment <!-- 1234567890 --> is not added.
I'm pretty sure I'm missing something here. I'm starting to believe that if I want to write to a response body served by a upstream server a filter may not be the answer. 
I've tried evanmiller.org guide and I found the section "3.2. Anatomy of an Upstream (a.k.a Proxy) Handler" (http://www.evanmiller.org/nginx-modules-guide.html#proxying) and I have the impression that this might help me finding the answer, but I'm failing to reproduce the example because at the moment I'm not as familiar with the guts of an handler as I am with a filter.
Anyway, I don't even know if an handler will do the trick. So any help is welcome :)
Thank you.

Date: Sat, 22 Sep 2012 01:45:40 +0800
Subject: Re: nginx filter to concat text to a response body
From: zhuzhaoyuan at gmail.com
To: nginx-devel at nginx.org

Hi Filipe,

On Sat, Sep 22, 2012 at 12:01 AM, Filipe Silva <fs20063 at outlook.com> wrote:




Hello,
I've been trying to produce a nginx filter to concat text to a response body but without success. 

An important detail is that it works with a nginx configured as a web server but not with a  nginx server configured as reverse proxy. 

Should I be using an handler instead?
Is this what you are looking for?
https://github.com/taobao/nginx-http-footer-filter 
Regards,
-- 
Joshua Zhu
Senior Software Engineer

Server Platforms Team at Taobao


_______________________________________________
nginx-devel mailing list
nginx-devel at nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20120922/a8668f7f/attachment.html>


More information about the nginx-devel mailing list