I have an Nginx cache server getting content from an origin server, the origin server sets Cache-Control
to Public
so my Nginx cache server can cache the content and make less requests to origin. But when serving to users, I don't want it to send the cache as Public
anymore, but set it to Private
so others (outside of this network) cannot cache it or modify it.
I still need it to pass a max-age and tried to do it by a custom header sent, but the if
condition fails.
this alone works OK:
add_header Cache-Control "private, max-age=$upstream_http_adr_private_cache_seconds";
this condition fails
if ($upstream_http_adr_private_cache_seconds) {
add_header Cache-Control "private, max-age=$upstream_http_adr_private_cache_seconds";
}
But this test also fails:
if ($upstream_http_adr_private_cache_seconds) {
return 404;
}
What am I doing wrong ? Or is there another way to alter the public
to private
?