V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
snw
V2EX  ›  问与答

Nginx 关不掉 gzip 是为什么?

  •  
  •   snw · 2014-10-16 22:37:42 +08:00 · 3309 次点击
    这是一个创建于 3478 天前的主题,其中的信息可能已经有所发展或是发生改变。
    尝试反代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   ·   我们的愿景   ·   实用小工具   ·   1492 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 23:56 · PVG 07:56 · LAX 16:56 · JFK 19:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.