How to send proxy cache status to backend server?

Maxim Dounin mdounin at
Wed Mar 19 14:15:32 UTC 2014


On Wed, Mar 19, 2014 at 03:30:03PM +0530, Makailol Charls wrote:

> One more thing I would like to know, would it be possible to proxy_pass
> request conditionally based on $upstream_cache_status ?
> For example here we set request header with proxy_set_header Cache-Status
> $upstream_cache_status; instead we can use condition like below,
> if ($upstream_cache_status = "BYPASS") {
>     proxy_pass http://someIP;
> }
> if ($upstream_cache_status = "MISS") {
>     proxy_pass http://anotherIP;
> }
> I tried this but could not find this working. I can set request header for
> backend with proxy_set_header but can not use this variable conditionally.

That's expected, as cache status isn't known at the rewrite phase 
when "if" directives are executed.  It's not even known if a 
request will be proxied at all.

Maxim Dounin

More information about the nginx mailing list