I think starting with a small snippet would be wisest:
location ^~ /test/ {
proxy_pass http://frontend;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-Port $server_port;
if ( $remote_addr ~* "123.123.123.123" ) {
proxy_cache cache_base;
proxy_cache_valid 720m;
}
}
So, in essence what we want to do is setup proxy caching based on a coniditonal IF statement.
The above does not work, as proxy_cache is not valid inside IF.
Does anyone know how to proxy cache based on a regexp match on one of the many nginx internal variables?
Note:
We want to basically disable / enable proxy_caching based on $remote_addr regexp. Not specify different proxy_cache values.
Thanks.
It seems that what you really want is to combine a geo variable with proxy_cache_bypass and proxy_no_cache:
'If' is generally a bad practive in nginx configuration. You can use map module to make things work. see http://nginx.org/en/docs/http/ngx_http_map_module.html http://wiki.nginx.org/HttpMapModule