Nginx to nginx proxy header problem

I have nginx proxying to nginx+fcgi and it looks like the Vary header is
being set twice. The reason for this config is that I intend to stick a
Varnish instance in between but wanted to make sure this was working
before.

Both instances have pretty much the same config.

From the frontend instance:
curl -I http://shop.carumba.org
HTTP/1.1 200 OK
Server: Hai
Date: Fri, 06 Mar 2009 05:02:38 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
Vary: Accept-Encoding
Set-Cookie: frontend=a5c6d3165679d1abdbc173205f2239da; expires=Fri, 06
Mar 2009 06:02:38 GMT; path=/; domain=shop.carumba.org; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0
Pragma: no-cache

From the backend instance:
HTTP/1.1 200 OK
Server: Hai
Date: Fri, 06 Mar 2009 05:02:56 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
Set-Cookie: frontend=9e9f8cb77126971bb0798fa7324bda30; expires=Fri, 06
Mar 2009 06:02:55 GMT; path=/; domain=shop.carumba.org; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0
Pragma: no-cache

As you can see, there is an additional Vary: header for some odd reason.

For completeness, the following are responses for a static file.
a001:/usr/local/nginx/conf/carumba$ curl -I --compressed
http://shop.carumba.org/skin/frontend/default/blank/css/reset.css
HTTP/1.1 200 OK
Server: Hai
Date: Fri, 06 Mar 2009 05:10:36 GMT
Content-Type: text/css
Last-Modified: Wed, 18 Feb 2009 07:22:32 GMT
Connection: keep-alive
Vary: Accept-Encoding
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000
Content-Encoding: gzip

a001:/usr/local/nginx/conf/carumba$ curl -I
http://shop.carumba.org/skin/frontend/default/blank/css/reset.css
HTTP/1.1 200 OK
Server: Hai
Date: Fri, 06 Mar 2009 05:10:49 GMT
Content-Type: text/css
Content-Length: 2834
Last-Modified: Wed, 18 Feb 2009 07:22:32 GMT
Connection: keep-alive
Vary: Accept-Encoding
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000
Accept-Ranges: bytes

This is with nginx 0.7.38

On Fri, Mar 06, 2009 at 06:12:55AM +0100, Jauder Ho wrote:

Server: Hai
Pragma: no-cache
Mar 2009 06:02:55 GMT; path=/; domain=shop.carumba.org; HttpOnly
For completeness, the following are responses for a static file.
Cache-Control: max-age=315360000
Connection: keep-alive
Vary: Accept-Encoding
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000
Accept-Ranges: bytes

This is with nginx 0.7.38

You should remove
gzip on;
on one of the nginxes. Or add
gzip_vary off;

Igor,

Thanks. Setting gzip_vary off on the backend server seems to do the
trick.

I opted not to set gzip to off as the backend is directly accessible and
I still wanted the benefits of having gzip on.

–Jauder

On Fri, Mar 06, 2009 at 06:57:25PM +0100, Jauder Ho wrote:

Thanks. Setting gzip_vary off on the backend server seems to do the
trick.

I opted not to set gzip to off as the backend is directly accessible and
I still wanted the benefits of having gzip on.

You should set
gzip on;
gzip_vary [on|off];

only on one nginx. On other you should just set
gzip off;

Setting gzip_vary to “on” or “off” depends whether you want to add
the “Veryi: Accept-Encoding” header.

The Nginx wiki states that gzip and gzip_vary can be set within a
location directive. However, it does not appear to be working for me.
Setting it within a server directive does work.

http://wiki.codemongers.com/NginxHttpGzipModule#gzip_vary

So is the wiki or code incorrect?

–Jauder

Igor S. wrote:

You should set
gzip on;
gzip_vary [on|off];

only on one nginx. On other you should just set
gzip off;

Setting gzip_vary to “on” or “off” depends whether you want to add
the “Veryi: Accept-Encoding” header.