You can use map for this... - http://nginx.org/en/docs/http/ngx_http_map_module.html#map map $upstream_http_x_secured_page $nocache { "search string" "1" default ""; } location /foo { ... proxy_no_cache $nocache; } Posted at Nginx Forum: https://forum.nginx.org/read.php?2,278558,278563#msg-278563