Nginx – Safari does not decompress gzip content when Content-Encoding is gzip,gzip

gziphhvmnginxsafari

Safari for OSX, iOS, and Windows is having issues decompressing Gzip content on my server after a recent server overhaul.

I moved from 1 server with Apache and PHP5-FPM to 3 servers. A load balancer and two servers running HHVM, all using Nginx.

I cannot determine what causes the decompression issue. It happens consistently on the same documents, but inconsistently throughout the website.

This thread loads fine.
https://kiwifar.ms/threads/sun-tzus-the-art-of-war.11304/

This thread does not.
https://kiwifar.ms/threads/andrew-dobson-aka-tom-preston.1933/page-590

What I receive instead on Safari is content that looks like this.

����z�H�6xl]E6�//S�.j�Ey��]���r�����H�$J �@-]����%̥͕���@)R�$چ�,a�-22222ތÿ<����^�Q4v����p���?l���%�Zް]�����%�w�v����%�s�0l�>L�����_B����vp�������ہx��v������ݵ���{n� ���W;��^���bd��|׵&�����!=@j�{��-���;    ��Gܫ�Q���?�V�   �:�]�v�)&�Ж׍�8�^�p�m�FQ4yX����UV����I�珫�Zm�:���¶�G[[[w]�*F�=h��ձu��{���(�&tCi���3;��vu�ҬԪ�0L=��|�%�n�R%ÑmG%QE��b(��2�}�͚8!������q/��'���G

This only happens in Safari.

Chromium? Works. Google Chrome? Works. IE10? Works. Mozilla? Works. Opera? Works. IceWeasle? Works. Android Chrome? Works. Dolphin Browser? Works.

I've enabled debugging in Safari. Here are the response headers.

Safari for Windows

Cache-Control:private, max-age=0
CF-RAY:20f2a2c627ff22ac-LAX
Connection:keep-alive
Content-Encoding:gzip, gzip
Content-Type:text/html; charset=UTF-8
Date:Sat, 01 Aug 2015 15:39:27 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Server:cloudflare-nginx
Transfer-Encoding:Identity
Vary:Accept-Encoding, Accept-Encoding
X-Frame-Options:SAMEORIGIN
X-Powered-By:HHVM/3.8.1

For contrast, here is Chromium, which works.

Chromium (Working)

cache-control:private, max-age=0
cf-ray:20f2a3b04a8d13c5-LAX
content-encoding:gzip
content-encoding:gzip
content-type:text/html; charset=UTF-8
date:Sat, 01 Aug 2015 15:40:05 GMT
expires:Thu, 19 Nov 1981 08:52:00 GMT
server:cloudflare-nginx
status:200 OK
vary:Accept-Encoding
vary:Accept-Encoding
version:HTTP/1.1
x-frame-options:SAMEORIGIN
x-powered-by:HHVM/3.8.1

This is the exact same document. The only difference appears to be that Safari sends "keep-alive", which is not present in Chromium. Maybe this is why it never decompresses? It never stops waiting for more gzip stuff?

Nginx config for Gzip. This applies to all three servers (both load balancer and nodes)

    gzip on;
    gzip_disable "msie6";

    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 32 8k;
    gzip_http_version 1.1;
    gzip_types text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;


    proxy_buffering off;

Additionally, here is the load config.

    upstream fruitbasket {
            server lime:443 weight=10;
            server lemon:443 weight=3;
    }

I have tried every conceivable configuration to fix this but nothing has helped.

Edit 1: After looking through the response headers of all other browsers, the Keep-Alive I mentioned was not found in any of them.

Edit 2: I can confirm that the issue is Content-Encoding:gzip, gzip. Any page with a single gzip loads. Safari doesn't know what to do with this encoding type.

Best Answer

My issue was specific. XenForo features automatic gzip as an application-level config option. If you are having this issue, make sure that your application does not also gzip before it reaches your server.

https://xenforo.com/help/config-php-options/