Issue with proxy_cache_key after rewrite

Maxim Dounin mdounin at mdounin.ru
Sat Dec 25 06:48:29 MSK 2010


Hello!

On Fri, Dec 24, 2010 at 11:57:30PM +0100, Sven 'Darkman' Michels wrote:

> Hi,
> 
> i've run a few tests with the nginx proxy module. I would like to have
> my content cached with the "$scheme$host$request_uri" key, like suggested
> on the wiki page[1]. So i've added the following:
> proxy_cache_key "$scheme$host$request_uri";
> 
> into the http {} block. After the test i've checked the keys which are used
> in the cached files and noticed that the key was
> httpmy_vhost/original_request_uri
> 
> but i've a perl module which does a internal_redirect which rewrites some
> paths like /olddir/ to /.
> 
> Now we have the following request:
> http//my_vhost/olddir/documents/test.pdf
> 
> so i thought the key should be
> httpmy_vhost/documents/test.pdf
> 
> but it was
> httpmy_vhost/olddir/documents/test.pdf
> 
> when i remove the proxy_cache_key from the config i get the following key:
> http://interal_host:internal_port/documents/test.pdf
> 
> so something here seems to be "strange". Because the default key is:
> default: $scheme$proxy_host$request_uri;
> 
> and now we see the following differences:
> first: $scheme seems to be http when beeing used, but http:// when default.
> second: the $request_uri is not rewritten when defined as key, but it seems
> to be rewritten by default.
> 
> Seems like a bug to me...?

Default listed in wiki/docs isn't what actually used by default as 
proxy_cache_key.  In russian docs[1] you may find something like

    By default value is similar to
    proxy_cache_key  $scheme$proxy_host$uri$is_args$args;

Word "similar" is key one.  Actual value can't be expressed with 
variables.  It's something like $proxy_url - but there are no such 
variable.

[1] http://sysoev.ru/nginx/docs/http/ngx_http_proxy_module.html#proxy_cache_key

Maxim Dounin



More information about the nginx mailing list