﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	uname	nginx_version
261	HEAD requests still have content-type when gzip on	Stephen Dendtler	Valentin V. Bartenev	"When using proxy_pass for HEAD requests, combined with gzip being turned on, nginx is returning body content even when the backend returns no content.  This is a bug as no content is supposed to be returned in a HEAD response.

We're consistently seeing 20 bytes of binary data being sent after the HEAD response headers in a separate packet, possibly corresponding to a gzip header for 0 bytes of content.

This seems to be confusing some proxies such as Apache when keepalives are enabled where it sends a HEAD request followed by a GET request.  Apache is accepting the content returned on the HEAD request without applying un-gzip methods, and prepending it to the content returned by the GET request as it's part of the same TCP stream.  While this is arguably a problem in Apache, if nginx's output conformed to the HTTP spec then this wouldn't be an issue.

Temporary workaround is to add this to the corresponding location definition:
    if ($request_method = HEAD ) {
        gzip              off;
    }

Sample gzip config:
        gzip              on;
        gzip_min_length   1000;
        gzip_buffers      12 32k;
        gzip_http_version 1.0;
        gzip_comp_level 6;
        gzip_proxied any;
        gzip_vary off;
        gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
        gzip_disable ""MSIE [1-6].(?!.*SV1)"";

Sample request to replicate the issue:
    HEAD / HTTP/1.1
    Host: www.example.com
    Accept-Encoding: gzip, deflate
    Connection: Keep-Alive


Headers from the upstream server will be returned (expected), along with 20 bytes of binary data (bug)."	defect	closed	minor		nginx-module	1.3.x	fixed	gzip		Linux - 2.6.32-71.el6.x86_64 #1 SMP Fri May 20 03:51:51 BST 2011 x86_64 x86_64 x86_64 GNU/Linux	"nginx version: nginx/1.3.9
TLS SNI support enabled
configure arguments: --prefix=/usr/local/PACKAGES/nginx-1.3.9 --with-poll_module --with-http_ssl_module --with-http_flv_module --with-openssl=/usr/local/PKG_BUILD/openssl-0.9.8r --with-pcre=/usr/local/PKG_BUILD/pcre-8.12 --add-module=nginx_uploadprogress_module --with-syslog --add-module=ngx_cache_purge-1.3 --with-file-aio --with-ld-opt=-ldl --add-module=nginx-sticky-module-1.1"
