nginx compression-at-edge (in front of a reverse proxy) compresses some content, not other ?

Ben DJ bendj095124367913213465 at gmail.com
Wed Apr 28 19:33:03 MSD 2010


Hi Igor,

On Tue, Apr 27, 2010 at 11:25 PM, Igor Sysoev <igor at sysoev.ru> wrote:
>> Any ideas why/where the .js is not getting gzipped?

> You may set on it on nginx side:
>       proxy_set_header     Accept-Encoding  "";

Done. Thanks.

> In your examples .js response has 304 code without body, so here is
> nothing to gzip, and .gif response has 404 code and it is not image,
> but text/html, so it is gzipped.

Yup.  Those 304s were a result of local caching in the client.
Cleared that, and retried -- getting 200s, as expected, BUT, still no
js gzip.

Turns out that there was another issue, caught @ varnish list ...
namely, that the js is being served with Content-Type: text/x-js --
which was NOT added to the nginx gzip-types.

The cause is,

  grep js /etc/apache2/mime.types
    application/javascript js
    text/x-js js

defined in the standard distro-release of apache2.  not mentioned at
all in the rfc (http://www.ietf.org/rfc/rfc4329.txt), but widely used,
apparently, nonetheless. so, added it to gzip types, and tried again.


now, headers show BOTH js & css being compressed, as intended,

----------------------------------------------------------
https://my.site.com/apostrophePlugin/js/jquery.autogrow.js


GET /apostrophePlugin/js/jquery.autogrow.js HTTP/1.1
Host: my.site.com
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.4) Gecko/20100417
Accept: */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: https://my.site.com/
Cookie: symfony=R%2Cq-BqTdX-ckfGCqHa2MnDsbJpd

HTTP/1.1 200 OK
Server: nginx/0.8.35
Date: Wed, 28 Apr 2010 15:09:34 GMT
Content-Type: text/x-js
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Last-Modified: Wed, 28 Apr 2010 04:42:23 GMT
Etag: "267f6-db6-48544a2d549c0"
Cache-Control: max-age=259200
Expires: Sat, 01 May 2010 15:09:34 GMT
X-Varnish: 1289869751 1289869733
Age: 283
Via: 1.1 varnish
Content-Encoding: gzip

----------------------------------------------------------
https://my.site.com/apostrophePlugin/css/a.css

GET /apostrophePlugin/css/a.css HTTP/1.1
Host: my.site.com
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.4) Gecko/20100417
Accept: text/css,*/*;q=0.1
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: https://my.site.com/
Cookie: symfony=R%2Cq-BqTdX-ckfGCqHa2MnDsbJpd

HTTP/1.1 200 OK
Server: nginx/0.8.35
Date: Wed, 28 Apr 2010 15:09:34 GMT
Content-Type: text/css
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Last-Modified: Wed, 28 Apr 2010 04:42:21 GMT
Etag: "26233-14e26-48544a2b6c540"
Cache-Control: max-age=259200
Expires: Sat, 01 May 2010 15:09:34 GMT
X-Varnish: 1289869748
Age: 0
Via: 1.1 varnish
Content-Encoding: gzip

----------------------------------------------------------

AND, the YSlow plugin now 'grades' the page an "A".

> BTW, why do you use varnish instead of nginx built-in proxy cache ?

I'd originally had Pound in front of varnish;  Nginx was a logical
choice to replace it, as a first step.

As for using it as a proxy cache ... Varnish provides all in-memory
caching.  I simply don't know if nginx.

Also, I use Varnish to provide a content-based parallel CDN.  Attempts
to do it with nginx failed, and, it appeared others were having issue
as well (http://groups.drupal.org/node/48182).  The nginx + varnish
solution works well.

> BTW, in 0.7.12+ you may use
>    gzip_disable  msie6;
> instead of
>    gzip_disable "MSIE [1-6].(?!.*SV1)";
> It's faster.

Missed that one completely.  Thanks.

> Also, "gzip_comp_level 1" is enough. 9th level simply eats more CPU, but
> do not produce proportional cmpression ratio. Say, 1 decreases file 2 times
> while 9 - only 2.5, but not 5 times.

I didn't realize that the difference was _that_ small ...

Thanks for the help!

Ben

>
>
> --
> Igor Sysoev
> http://sysoev.ru/en/
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://nginx.org/mailman/listinfo/nginx
>



More information about the nginx mailing list