Help about how proxy_cache to store differet cache file by http header vary Accept-Encoding like squ

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

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?

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:[email protected]]
·¢ËÍʱ¼ä: 2010Äê3ÔÂ4ÈÕ 2:25
ÊÕ¼þÈË: [email protected]
Ö÷Ìâ: 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
[email protected]
http://nginx.org/mailman/listinfo/nginx

2010/3/5 杨春宇 [email protected]:

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;
#the following uses a combination of URI and the accept-encoding as a
proxy cache key
proxy_cache_key “$host$request_uri$myae”;

RPM

Thanks a lot, This solution is good

Thanks again!

    yahwist

-----邮件原件-----
发件人: Ryan M. [mailto:[email protected]]
发送时间: 2010年3月12日 13:10
收件人: [email protected]
主题: Re: help about how proxy_cache to store differet cache file by
httpheader vary Accept-Encoding like squid

2010/3/5 î´º [email protected]:

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;
#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
[email protected]
http://nginx.org/mailman/listinfo/nginx

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, 杨春宇 [email protected] 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
[email protected]
nginx Info Page


RPM