# Help about how proxy\_cache to store differet cache file by http header vary Accept-Encoding like squ

**URL:** <https://www.ruby-forum.com/t/help-about-how-proxy-cache-to-store-differet-cache-file-by-http-header-vary-accept-encoding-like-squ/184511>\
**Category:** NGINX\
**Created:** [March 3, 2010, 6:20pm UTC](https://www.ruby-forum.com/t/help-about-how-proxy-cache-to-store-differet-cache-file-by-http-header-vary-accept-encoding-like-squ/184511 "2010-03-03T18:20:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yangchunyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/58956e/32.png) [@yangchunyu](https://www.ruby-forum.com/u/yangchunyu)\
**Post date:** [March 3, 2010, 6:20pm UTC](https://www.ruby-forum.com/t/help-about-how-proxy-cache-to-store-differet-cache-file-by-http-header-vary-accept-encoding-like-squ/184511/1 "2010-03-03T18:20:18Z")

</div>

We use nginx as reserve proxy server and want use proxy\_cache to replace  
squid.  
There are apache servers behind nginx, we use deflate module to compress  
text/html pages.  
The problem is if proxy\_cache has cached the compressed page but the  
client  
side that request page does not support uncompress, the page can not be  
see  
correctly.  
I know squid using http header Accept-Encoding to store different cache  
file, but there is no way to use it in nginx proxy\_cache\_key.

Thanks  
yahwist

---

<div class="post-metadata">

**Author:** ![yangchunyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/58956e/32.png) [@yangchunyu](https://www.ruby-forum.com/u/yangchunyu)\
**Post date:** [March 3, 2010, 7:25pm UTC](https://www.ruby-forum.com/t/help-about-how-proxy-cache-to-store-differet-cache-file-by-http-header-vary-accept-encoding-like-squ/184511/2 "2010-03-03T19:25:53Z")

</div>

On Thu, 2010-03-04 at 01:19 +0800, yangchunyu wrote:

> We use nginx as reserve proxy server and want use proxy\_cache to replace squid.  
> There are apache servers behind nginx, we use deflate module to compress text/html pages.  
> The problem is if proxy\_cache has cached the compressed page but the client side that request page does not support uncompress, the page can not be see correctly.  
> I know squid using http header Accept-Encoding to store different cache file, but there is no way to use it in nginx proxy\_cache\_key.

You can try to use proxy\_cache\_key to define caching key ( i don’t  
know however if you find variable that will do trick ).

The other method i would think of is not letting nginx to cache  
compressed content. And i don’t mean caching or not depend on  
whether backend response is compressed or not - i mean forcing  
uncompressed transmission between nginx and backends.  
You may even gain another benefit - lessen the compression burden  
on backends which may give you spare cpu cycles on them.

I believe  
proxy\_set\_header Accept-Encoding “”;  
in proxying location is the way to go.

–  
Miroslaw “Psyborg” Jaworski  
GCS/IT d- s+:+ a C++$ UBI++++$ P+++$ L- E— W++(+++)$ N++ o+ K- w-- O-  
M- V- PS+ PE++ Y+ PGP t 5? X+ R++ !tv b++(+++) DI++ D+ G e\* h++ r+++ y?

---

<div class="post-metadata">

**Author:** ![yangchunyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/58956e/32.png) [@yangchunyu](https://www.ruby-forum.com/u/yangchunyu)\
**Post date:** [March 5, 2010, 8:24am UTC](https://www.ruby-forum.com/t/help-about-how-proxy-cache-to-store-differet-cache-file-by-http-header-vary-accept-encoding-like-squ/184511/3 "2010-03-05T08:24:55Z")

</div>

I think use proxy\_cache\_key to define caching key is good idea .  
but I do not know which variable to use that can distinguish client side  
support compressed or compressed content and store the different cache  
file.

Can Igor S. help me . Thanks a lot.

```
                      yangchunyu

```

-----ÓÊ¼þÔ­¼þ-----  
·¢¼þÈË: Miros?aw Jaworski [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
·¢ËÍÊ±¼ä: 2010Äê3ÔÂ4ÈÕ 2:25  
ÊÕ¼þÈË: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Ö÷Ìâ: Re: help about how proxy\_cache to store differet cache file by  
httpheader vary Accept-Encoding like squid

On Thu, 2010-03-04 at 01:19 +0800, yangchunyu wrote:

> We use nginx as reserve proxy server and want use proxy\_cache to replace  
> squid.  
> There are apache servers behind nginx, we use deflate module to compress  
> text/html pages.  
> The problem is if proxy\_cache has cached the compressed page but the  
> client side that request page does not support uncompress, the page can  
> not  
> be see correctly.  
> I know squid using http header Accept-Encoding to store different cache  
> file, but there is no way to use it in nginx proxy\_cache\_key.

You can try to use proxy\_cache\_key to define caching key ( i don’t  
know however if you find variable that will do trick ).

The other method i would think of is not letting nginx to cache  
compressed content. And i don’t mean caching or not depend on  
whether backend response is compressed or not - i mean forcing  
uncompressed transmission between nginx and backends.  
You may even gain another benefit - lessen the compression burden  
on backends which may give you spare cpu cycles on them.

I believe  
proxy\_set\_header Accept-Encoding “”;  
in proxying location is the way to go.

–  
Miroslaw “Psyborg” Jaworski  
GCS/IT d- s+:+ a C++$ UBI++++$ P+++$ L- E— W++(+++)$ N++ o+ K- w-- O-  
M- V- PS+ PE++ Y+ PGP t 5? X+ R++ !tv b++(+++) DI++ D+ G e\* h++ r+++ y?

* * *

nginx mailing list  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> **[mailman.nginx.org archive](http://mailman.nginx.org/pipermail/)**

---

<div class="post-metadata">

**Author:** ![yangchunyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/58956e/32.png) [@yangchunyu](https://www.ruby-forum.com/u/yangchunyu)\
**Post date:** [March 12, 2010, 6:10am UTC](https://www.ruby-forum.com/t/help-about-how-proxy-cache-to-store-differet-cache-file-by-http-header-vary-accept-encoding-like-squ/184511/4 "2010-03-12T06:10:27Z")

</div>

2010/3/5 æ¨æ˜¥å®‡ [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I think use proxy\_cache\_key to define caching key is good idea .  
> but I do not know which variable to use that can distinguish client side  
> support compressed or compressed content and store the different cache file.

# Here’s an example I’ve used. Of course the upstream server must return compressed responses to HTTP/1.0 requests, which many do not by default:

## #normalize all accept-encoding headers to just gzip or the empty string set $myae “”; if ($http\_accept\_encoding ~\* gzip) { set $myae “gzip”; } #the following prevents comressed responses from backend proxy\_set\_header Accept-Encoding $myae; proxy\_pass [http://backend](http://backend); #the following uses a combination of URI and the accept-encoding as a proxy cache key proxy\_cache\_key “$host$request\_uri$myae”;

RPM

---

<div class="post-metadata">

**Author:** ![yangchunyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/58956e/32.png) [@yangchunyu](https://www.ruby-forum.com/u/yangchunyu)\
**Post date:** [March 12, 2010, 2:39pm UTC](https://www.ruby-forum.com/t/help-about-how-proxy-cache-to-store-differet-cache-file-by-http-header-vary-accept-encoding-like-squ/184511/5 "2010-03-12T14:39:41Z")

</div>

Thanks a lot, This solution is good

Thanks again!

```
    yahwist

```

-----é‚®ä»¶åŽŸä»¶-----  
å‘ä»¶äºº: Ryan M. [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
å‘é€æ—¶é—´: 2010å¹´3æœˆ12æ—¥ 13:10  
æ”¶ä»¶äºº: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
ä¸»é¢˜: Re: help about how proxy\_cache to store differet cache file by  
httpheader vary Accept-Encoding like squid

2010/3/5 î´º [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I think use proxy\_cache\_key to define caching key is good idea .  
> but I do not know which variable to use that can distinguish client side  
> support compressed or compressed content and store the different cache file.

# Here’s an example I’ve used. Of course the upstream server must return compressed responses to HTTP/1.0 requests, which many do not by default:

## #normalize all accept-encoding headers to just gzip or the empty string set $myae “”; if ($http\_accept\_encoding ~\* gzip) { set $myae “gzip”; } #the following prevents comressed responses from backend proxy\_set\_header Accept-Encoding $myae; proxy\_pass [http://backend](http://backend); #the following uses a combination of URI and the accept-encoding as a proxy cache key proxy\_cache\_key “$host$request\_uri$myae”;

RPM

* * *

nginx mailing list  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> **[mailman.nginx.org archive](http://mailman.nginx.org/pipermail/)**

---

<div class="post-metadata">

**Author:** ![yangchunyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/58956e/32.png) [@yangchunyu](https://www.ruby-forum.com/u/yangchunyu)\
**Post date:** [March 12, 2010, 5:08pm UTC](https://www.ruby-forum.com/t/help-about-how-proxy-cache-to-store-differet-cache-file-by-http-header-vary-accept-encoding-like-squ/184511/6 "2010-03-12T17:08:21Z")

</div>

You can also make the if block more complicated to remove  
accept-encoding for types you know will not be compressed (.gif, .png,  
.mpg, etc)

On Fri, Mar 12, 2010 at 7:38 AM, æ¨æ˜¥å®‡ [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> å‘é€æ—¶é—´: 2010å¹´3æœˆ12æ—¥ 13:10  
> compressed responses to HTTP/1.0 requests, which many do not by  
> #the following uses a combination of URI and the accept-encoding as a
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
RPM
