Gzipped content being sent to HTTP/1.0 clients?

Nicholas Sherlock n.sherlock at gmail.com
Mon Aug 1 02:42:50 UTC 2011


Hi everyone,

I'm using gzip and proxy_cache together, proxying to an Apache backend.
Some of my clients are complaining that they are getting gzipped content
which their browser is displaying without un-gzipping it, presumably
because they getting served gzipped content when their browser doesn't
support it.

I noticed that HTTP/1.0 clients are getting served gzipped content even
though gzip_http_version is set to 1.1. That should never happen, right?
I guess it is because a 1.1 client requested it first, and it got
cached? Here's the log of an HTTP/1.0 client (wget) grabbing the resource:

wget -d
"http://www.chickensmoothie.com/Forum/style.php?id=9&lang=en&v=1312084157"

---request begin---
GET /Forum/style.php?id=9&lang=en&v=1312084157 HTTP/1.0
User-Agent: Wget/1.12 (cygwin)
Accept: */*
Host:www.chickensmoothie.com
Connection: Keep-Alive

---response begin---
HTTP/1.1 200 OK
Server: nginx/1.0.4
Date: Mon, 01 Aug 2011 00:23:27 GMT
Content-Type: text/css; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.3.5-1ubuntu7.2
Expires: Wed, 09 Nov 2011 00:22:33 GMT
Last-Modified: Sun, 31 Jul 2011 03:49:17 GMT
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 15750

---response end---
200 OK
Registered socket 3 for persistent reuse.
URI content encoding = `UTF-8'
Length: 15750 (15K) [text/css]
Saving to: `style.php at id=9&lang=en&v=1312084157.4'

2011-08-01 12:22:35 (21.4 KB/s) -
`style.php at id=9&lang=en&v=1312084157.4' saved [15750/15750]


Note that the backend isn't sending a gzipped response to Nginx:


wget --header="Host:www.chickensmoothie.com" -d
"http://localhost:8080/Forum/style.php?id=9&lang=en&v=1312084157"

---request begin---
GET /Forum/style.php?id=9&lang=en&v=1312084157 HTTP/1.0
User-Agent: Wget/1.12 (linux-gnu)
Accept: */*
Host:www.chickensmoothie.com
Connection: Keep-Alive

---response begin---
HTTP/1.1 200 OK
Date: Mon, 01 Aug 2011 00:32:28 GMT
Server: Apache/2.2.17 (Ubuntu)
X-Powered-By: PHP/5.3.5-1ubuntu7.2
X-Accel-Expires: 600
Expires: Wed, 09 Nov 2011 00:32:28 GMT
Last-Modified: Sun, 31 Jul 2011 03:49:17 GMT
Vary: Accept-Encoding
Connection: close
Content-Type: text/css; charset=UTF-8

---response end---
200 OK
Length: unspecified [text/css]
Saving to: `style.php?id=9&lang=en&v=1312084157.5'

2011-08-01 00:32:28 (377 MB/s) - `style.php?id=9&lang=en&v=1312084157.5'
saved [78125]


Here's my config details:

nginx: nginx version: nginx/1.0.4

gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_buffers 16 4k;
gzip_types text/plain text/html text/css application/json
application/x-javascript text/xml application/xml application/xml+rss
text/javascript;
gzip_vary on;
gzip_http_version 1.1;

proxy_temp_path /caches/proxy_temp;
proxy_cache_path /caches/nginx levels=1:2 keys_zone=one:50m inactive=3d
max_size=10g;

server {
	listen 80 default;
	server_name _;

	index index.php index.html index.htm;

	location /Forum/style.php {
		proxy_passhttp://127.0.0.1:8080;
		proxy_redirect off;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header Host $host;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_read_timeout 600;
		proxy_intercept_errors on;

		proxy_cache one;
		proxy_cache_key $host$request_uri;
		proxy_cache_valid 200 301 302 2000m;
		proxy_cache_use_stale error timeout invalid_header updating;
	}
}

I've disabled the proxy_cache for the moment, which seems to fix this
behaviour (HTTP/1.0 clients get a plain response, HTTP/1.1 clients who
send an accept-encoding:gzip get a gzipped response).

Cheers,
Nicholas Sherlock



More information about the nginx mailing list