# Gzipped content being sent to HTTP/1.0 clients?

**URL:** <https://www.ruby-forum.com/t/gzipped-content-being-sent-to-http-1-0-clients/210144>\
**Category:** NGINX\
**Created:** [August 1, 2011, 6:55am UTC](https://www.ruby-forum.com/t/gzipped-content-being-sent-to-http-1-0-clients/210144 "2011-08-01T06:55:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [August 1, 2011, 6:55am UTC](https://www.ruby-forum.com/t/gzipped-content-being-sent-to-http-1-0-clients/210144/1 "2011-08-01T06:55:01Z")

</div>

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](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@id=9&lang=en&v=1312084157.4’

2011-08-01 12:22:35 (21.4 KB/s) -  
`style.php@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](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

---

<div class="post-metadata">

**Author:** ![Nicholas\_Sherlock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9fc29f/32.png) [@Nicholas\_Sherlock](https://www.ruby-forum.com/u/Nicholas_Sherlock)\
**Post date:** [August 1, 2011, 7:38am UTC](https://www.ruby-forum.com/t/gzipped-content-being-sent-to-http-1-0-clients/210144/2 "2011-08-01T07:38:51Z")

</div>

proxy cache key needs to include accept encoding as php does the gzip  
for  
phpbb3

---

<div class="post-metadata">

**Author:** ![Nicholas\_Sherlock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9fc29f/32.png) [@Nicholas\_Sherlock](https://www.ruby-forum.com/u/Nicholas_Sherlock)\
**Post date:** [August 1, 2011, 8:09am UTC](https://www.ruby-forum.com/t/gzipped-content-being-sent-to-http-1-0-clients/210144/3 "2011-08-01T08:09:03Z")

</div>

On Mon, Aug 01, 2011 at 02:42:50PM +1200, Nicholas Sherlock wrote:

> I guess it is because a 1.1 client requested it first, and it got  
> Connection: Keep-Alive  
> Vary: Accept-Encoding  
> 2011-08-01 12:22:35 (21.4 KB/s) -  
> GET /Forum/style.php?id=9&lang=en&v=1312084157 HTTP/1.0  
> X-Accel-Expires: 600
> 
> gzip\_buffers 16 4k;  
> server {  
> proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;
> 
> 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).

Add  
proxy\_set\_header Accept-Encoding “”;  
to disable gzipping on backend.

or add a gzip flag in cache key:

map $http\_accept\_encoding $gzip {  
default “”;  
~gzip " gzip";  
}

```
 proxy_cache_key "$host$request_uri$gzip";

```

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![Nicholas\_Sherlock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9fc29f/32.png) [@Nicholas\_Sherlock](https://www.ruby-forum.com/u/Nicholas_Sherlock)\
**Post date:** [August 1, 2011, 5:46pm UTC](https://www.ruby-forum.com/t/gzipped-content-being-sent-to-http-1-0-clients/210144/4 "2011-08-01T17:46:17Z")

</div>

On 8/1/11 1:19 AM, “SplitIce” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> proxy cache key needs to include accept encoding as php does the gzip for  
> phpbb3

We always strip of Accept-encoding header whenever we proxy or use  
fastcgi.  
This keeps all the config/logic in nginx.

–  
Brian A.
