Ways to control the gzip_vary directive from nginx 0.6.34 and above?

Hello,

Nginx 0.6.34 and above have changed the gzip_vary directive to add
the “Vary: Accept-Encoding” header to uncompressed responses as well as
compressed responses.

The change is specifically:

"
Changes with nginx 0.6.34 27 Nov
2008

*) Change: now the "gzip_vary" directive turned on issues a
   "Vary: Accept-Encoding" header line for uncompressed responses 

too.
"

Unfortunately for me, this change prevents us from using our CDN.
Our CDN will not cache requests for non gzipped content that has the
Vary header. Thus, this defeats the purpose of our CDN for a large part
of our image and audio content.

For the time being, this means I have to remove the changes to the
nginx_http_gzip_static_module.c to prevent this header from showing up.

Short of hacking nginx_http_gzip_static_module.c, is there a way to
prevent
this Vary header from showing up with non-gzipped content? If not, would
it
be possible to make this directive configurable?

Also may I ask why this change was made? Is there something I am
missing relating to the HTTP spec for this?

Thank you for you time,
Zev B.

Nginx 0.6.34 and above have changed the gzip_vary directive to add the
“Vary: Accept-Encoding” header to uncompressed responses as well as
compressed responses.

This should only be the case for the matched gzip_types, though not
all
uncompressed responses. Have you included (inappropriate for
compression)
image and audio types in gzip_types? If so, remove them, and you should
be
done (unless there is a bug in nginx -> but I haven’t seen a similar
thing
happen on my servers).

  • Jeff

On Tue, Sep 15, 2009 at 01:07:50PM +0900, Zev B. wrote:

nginx_http_gzip_static_module.c to prevent this header from showing up.

Short of hacking nginx_http_gzip_static_module.c, is there a way to prevent
this Vary header from showing up with non-gzipped content? If not, would it
be possible to make this directive configurable?

“gzip_vary on” adds the “Vary” header only to non-gzipped responses
those
can be gzipped, but were not gzipped for some reasons: gzip_disable,
gzip_proxied, and gzip_http_version disable gzipping for some particular
reason.

Since image and audio content are not gzipable content at all, nginx
will
not add this header in those responses.

Also may I ask why this change was made? Is there something I am
missing relating to the HTTP spec for this?

The modern Squid versions keep several responses: gzipped and
non-gzipped
ones and use appropriate one depending on “Accept-Encoding” header.

On Tue, Sep 15, 2009 at 02:38:48PM +0900, Zev B. wrote:

uncompressed responses. Have you included (inappropriate for compression)
gzip on;

Set a vary header so downstream proxies don’t send cached gzipped

content to IE6
gzip_vary on;

But with these commands things like jpgs and mp3s are still getting the
Vary: Accept-Encoding header, even though they are not compressed.
Is there something I am missing?

It should not.
Could you create debug log ?

On 09/15/2009 02:48 PM, Igor S. wrote:

On Tue, Sep 15, 2009 at 02:38:48PM +0900, Zev B. wrote:

gzip_min_length 1100;

But with these commands things like jpgs and mp3s are still getting the
Vary: Accept-Encoding header, even though they are not compressed.
Is there something I am missing?

It should not.
Could you create debug log ?

Sure.

I have attached a debug log from 0.6.39 that has the Vary when it should
not. If you would like I can also attach a debug log from 0.6.32 that
does not include the Vary (which is what I need).

Thanks,
Zev

Hello,

On 09/15/2009 01:47 PM, Jeff W. wrote:

happen on my servers).
I don’t think I have, but just in case here is a copy of my gzip
commands:


Serve up static compressed items

gzip_static on;

Compression

gzip on;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_proxied any;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain text/html text/css application/x-javascript
text/xml application/xml application/xml+rss text/javascript;

Some version of IE 6 don’t handle compression well on some mime-types,

so just disable for them
gzip_disable “MSIE [1-6].(?!.*SV1)”;

Set a vary header so downstream proxies don’t send cached gzipped

content to IE6
gzip_vary on;

But with these commands things like jpgs and mp3s are still getting the
Vary: Accept-Encoding header, even though they are not compressed.
Is there something I am missing?

Thanks,
Zev

Hello,

On 09/15/2009 05:23 PM, Igor S. wrote:

On Tue, Sep 15, 2009 at 04:20:48PM +0900, Zev B. wrote:

I have attached a debug log from 0.6.39 that has the Vary when it should
not. If you would like I can also attach a debug log from 0.6.32 that
does not include the Vary (which is what I need).

This bug was fixed in 0.7.9.
The attached patch fixes it in 0.6.x, if you prefer to stay on this version.

Thank you for the patch!
Unfortunately, it nor does the latest 0.7.62 seem to fix it.
I am still getting the Vary: Accept-Encoding header for non gzip stuff.
In both this patch and with 0.7.62

wget -S -O /dev/null http://localhost:8989/images/sprites/badge.png

HTTP/1.1 200 OK
Server: nginx/0.6.39
Date: Tue, 15 Sep 2009 09:15:02 GMT
Content-Type: image/png
Content-Length: 20031
Last-Modified: Tue, 08 Sep 2009 07:50:52 GMT
Connection: keep-alive
Vary: Accept-Encoding
Expires: Wed, 16 Sep 2009 09:15:02 GMT
Cache-Control: max-age=86400
Accept-Ranges: bytes


HTTP/1.1 200 OK
Server: nginx/0.7.62
Date: Tue, 15 Sep 2009 09:28:02 GMT
Content-Type: image/png
Content-Length: 20031
Last-Modified: Tue, 08 Sep 2009 07:50:52 GMT
Connection: keep-alive
Vary: Accept-Encoding
Expires: Wed, 16 Sep 2009 09:28:02 GMT
Cache-Control: max-age=86400
Accept-Ranges: bytes

— HERE is a good response example —

HTTP/1.1 200 OK
Server: nginx/0.6.32
Date: Tue, 15 Sep 2009 09:32:50 GMT
Content-Type: image/png
Content-Length: 20031
Last-Modified: Tue, 08 Sep 2009 07:50:52 GMT
Connection: keep-alive
Expires: Wed, 16 Sep 2009 09:32:50 GMT
Cache-Control: max-age=86400
Accept-Ranges: bytes

Thanks,
Zev

On Tue, Sep 15, 2009 at 06:33:38PM +0900, Zev B. wrote:

This bug was fixed in 0.7.9.
HTTP/1.1 200 OK

Expires: Wed, 16 Sep 2009 09:28:02 GMT
Content-Length: 20031
Last-Modified: Tue, 08 Sep 2009 07:50:52 GMT
Connection: keep-alive
Expires: Wed, 16 Sep 2009 09:32:50 GMT
Cache-Control: max-age=86400
Accept-Ranges: bytes

I could not reproduce these responses on 0.8.15, 0.7.62 and patched
0.6.39.
Are you sure that you have no “image/png” in gzip_types ?

On Tue, Sep 15, 2009 at 01:54:53PM +0400, Igor S. wrote:

does not include the Vary (which is what I need).
wget -S -O /dev/null http://localhost:8989/images/sprites/badge.png
Cache-Control: max-age=86400
Connection: keep-alive
Date: Tue, 15 Sep 2009 09:32:50 GMT
Content-Type: image/png
Content-Length: 20031
Last-Modified: Tue, 08 Sep 2009 07:50:52 GMT
Connection: keep-alive
Expires: Wed, 16 Sep 2009 09:32:50 GMT
Cache-Control: max-age=86400
Accept-Ranges: bytes

I could not reproduce these responses on 0.8.15, 0.7.62 and patched 0.6.39.
Are you sure that you have no “image/png” in gzip_types ?

Sorry, I missed “gzip_static on”: it caused the problem.

On Tue, Sep 15, 2009 at 04:20:48PM +0900, Zev B. wrote:

gzip_http_version 1.1;
content to IE6
Sure.

I have attached a debug log from 0.6.39 that has the Vary when it should
not. If you would like I can also attach a debug log from 0.6.32 that
does not include the Vary (which is what I need).

This bug was fixed in 0.7.9.
The attached patch fixes it in 0.6.x, if you prefer to stay on this
version.

On Tue, Sep 15, 2009 at 02:05:35PM +0400, Igor S. wrote:

I have attached a debug log from 0.6.39 that has the Vary when it should
In both this patch and with 0.7.62
I could not reproduce these responses on 0.8.15, 0.7.62 and patched 0.6.39.
Are you sure that you have no “image/png” in gzip_types ?

Sorry, I missed “gzip_static on”: it caused the problem.

The attached patch fixes this bug on 0.8.15 and 0.7.62.

On 09/15/2009 07:28 PM, Igor S. wrote:

On Tue, Sep 15, 2009 at 04:20:48PM +0900, Zev B. wrote:
Unfortunately, it nor does the latest 0.7.62 seem to fix it.
I am still getting the Vary: Accept-Encoding header for non gzip stuff.
In both this patch and with 0.7.62

I could not reproduce these responses on 0.8.15, 0.7.62 and patched 0.6.39.
Are you sure that you have no “image/png” in gzip_types ?

Sorry, I missed “gzip_static on”: it caused the problem.

The attached patch fixes this bug on 0.8.15 and 0.7.62.

Cool!
This seems to work, although now requests from browsers that do not
support compression get the Vary header. This is probably fine for our
CDN.

curl -o /dev/null -D - --compress
http://localhost:8989/images/sprites/badge.png

HTTP/1.1 200 OK
Server: nginx/0.7.62
Date: Tue, 15 Sep 2009 10:55:18 GMT
Content-Type: image/png
Content-Length: 20031
Last-Modified: Tue, 08 Sep 2009 07:50:52 GMT
Connection: keep-alive
Expires: Wed, 16 Sep 2009 10:55:18 GMT
Cache-Control: max-age=86400
Accept-Ranges: bytes

wget -S -O /dev/null http://localhost:8989/images/sprites/badge.png

HTTP/1.1 200 OK
Server: nginx/0.7.62
Date: Tue, 15 Sep 2009 10:54:43 GMT
Content-Type: image/png
Content-Length: 20031
Last-Modified: Tue, 08 Sep 2009 07:50:52 GMT
Connection: keep-alive
Vary: Accept-Encoding
Expires: Wed, 16 Sep 2009 10:54:43 GMT
Cache-Control: max-age=86400
Accept-Ranges: bytes

Any chance of getting a patch for 0.6?

Thanks again!
Zev

On Sep 15, 2009, at 8:20 PM, Igor S. wrote:

This seems to work, although now requests from browsers that do not
support compression get the Vary header. This is probably fine for
our CDN.

Any chance of getting a patch for 0.6?

The combined patch is attached (including the first one).

Excellent! This works.

curl -o /dev/null -D - --compress
http://localhost:8989/images/sprites/badge.png
HTTP/1.1 200 OK
Server: nginx/0.6.39
Date: Tue, 15 Sep 2009 12:38:11 GMT
Content-Type: image/png
Content-Length: 20031
Last-Modified: Tue, 08 Sep 2009 07:50:52 GMT
Connection: keep-alive
Expires: Wed, 16 Sep 2009 12:38:11 GMT
Cache-Control: max-age=86400
Accept-Ranges: bytes

curl -o /dev/null -D - --compress
http://localhost:8989/stylesheets/base2_packaged.css
HTTP/1.1 200 OK
Server: nginx/0.6.39
Date: Tue, 15 Sep 2009 12:38:03 GMT
Content-Type: text/css
Content-Length: 34300
Last-Modified: Tue, 08 Sep 2009 07:51:31 GMT
Connection: keep-alive
Vary: Accept-Encoding
Content-Encoding: gzip
Expires: Wed, 16 Sep 2009 12:38:03 GMT
Cache-Control: max-age=86400

Thanks a lot!

Zev

On Tue, Sep 15, 2009 at 08:04:49PM +0900, Zev B. wrote:

On 09/15/2009 05:23 PM, Igor S. wrote:

Server: nginx/0.7.62
wget -S -O /dev/null http://localhost:8989/images/sprites/badge.png
Expires: Wed, 16 Sep 2009 10:54:43 GMT
Cache-Control: max-age=86400
Accept-Ranges: bytes

Any chance of getting a patch for 0.6?

The combined patch is attached (including the first one).