# Nginx to nginx proxy header problem

**URL:** <https://www.ruby-forum.com/t/nginx-to-nginx-proxy-header-problem/162137>\
**Category:** NGINX\
**Created:** [March 6, 2009, 6:12am UTC](https://www.ruby-forum.com/t/nginx-to-nginx-proxy-header-problem/162137 "2009-03-06T06:12:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jauderho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/839c29/32.png) [@jauderho](https://www.ruby-forum.com/u/jauderho)\
**Post date:** [March 6, 2009, 6:12am UTC](https://www.ruby-forum.com/t/nginx-to-nginx-proxy-header-problem/162137/1 "2009-03-06T06:12:55Z")

</div>

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://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](http://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](http://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://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://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

---

<div class="post-metadata">

**Author:** ![jauderho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/839c29/32.png) [@jauderho](https://www.ruby-forum.com/u/jauderho)\
**Post date:** [March 6, 2009, 8:45am UTC](https://www.ruby-forum.com/t/nginx-to-nginx-proxy-header-problem/162137/2 "2009-03-06T08:45:17Z")

</div>

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](http://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;

---

<div class="post-metadata">

**Author:** ![jauderho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/839c29/32.png) [@jauderho](https://www.ruby-forum.com/u/jauderho)\
**Post date:** [March 6, 2009, 6:57pm UTC](https://www.ruby-forum.com/t/nginx-to-nginx-proxy-header-problem/162137/3 "2009-03-06T18:57:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jauderho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/839c29/32.png) [@jauderho](https://www.ruby-forum.com/u/jauderho)\
**Post date:** [March 7, 2009, 11:25am UTC](https://www.ruby-forum.com/t/nginx-to-nginx-proxy-header-problem/162137/4 "2009-03-07T11:25:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jauderho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/839c29/32.png) [@jauderho](https://www.ruby-forum.com/u/jauderho)\
**Post date:** [March 7, 2009, 8:44pm UTC](https://www.ruby-forum.com/t/nginx-to-nginx-proxy-header-problem/162137/5 "2009-03-07T20:44:14Z")

</div>

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](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.
