Nginx 关不掉 gzip 是为什么? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
snw
V2EX    问与答

Nginx 关不掉 gzip 是为什么?

  •  
  •   snw 2014-10-16 22:37:42 +08:00 3816 次点击
    这是一个创建于 4013 天前的主题,其中的信息可能已经有所发展或是发生改变。
    尝试反代Google,由于需要进行替换,所以要关掉gzip。我在server段加了以下两句:
    gzip off;
    gzip_static off;

    测试后发现,
    (1) IE11访问是不压缩的,Response header的Transfer-Encoding是chunked,代码被成功替换。
    (2) 用orbit downloader下载下来的文件也是成功替换。
    (3) 但是用Firefox 33和Chrome 38访问,Response header却有Content-Encoding: "gzip",代码没有被替换。

    我甚至尝试在编译时去除 --with-http_gunzip_module 和 --with-http_gzip_static_module ,结果Response header还是有gzip。

    这究竟是什么原因?


    nginx的配置文件:
    https://github.com/shenyqwilliam/google-reverse-proxy/blob/master/google-reverse-proxy.conf

    Demo网站(请忽略证书问题):
    https://vmb.host.lith.tk/

    nginx信息:
    nginx version: nginx/1.6.2
    built by gcc 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC)
    TLS SNI support enabled
    configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_spdy_module --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --add-module=/usr/local/src/ngx_http_substitutions_filter_module/
    第 1 条附言    2014-10-16 23:42:13 +08:00
    又试了试,原来不是反代服务器的问题,而是Google自己进行了gzip。
    问题是我明明已经加了proxy_set_header Accept-Encoding ""; ,为什么google还是会返回gzip?
    更奇怪的是,IE11返回的就不是gzip,而Firefox和Chrome即使user-agent伪装成IE11,依然会被gzip。
    2 条回复    2020-05-20 07:59:22 +08:00
    yfgeek
        1
    yfgeek  
       2020-05-20 01:35:20 +08:00
    参考这个文章:
    https://ialloc.org/blog/how-nginx-gzip-works/#vary-accept-encoding
    ```
    proxy_set_header Accept-Encoding "";
    ```
    就好了
    snw
        2
    snw  
    OP
       2020-05-20 07:59:22 +08:00 via Android
    @yfgeek
    问题补充写了,加了这句也没用。
    几年前的事,现在无法再验证。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1085 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 29ms UTC 18:17 PVG 02:17 LAX 11:17 JFK 14:17
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86