Nginx add_header and cache management

When you use the add_header directive in nginx, the header is added to the response coming from the source server.

Let's say that the source server returns general cache control, max-age = 60. But in the nginx reverse proxy, you set something like:

add_header cache-control public, max-age = 10

What does it do? There are two different scenarios that I can think of:

1) Nginx looks at the cache control header from the source server and stores the contents in the cache after 60 seconds. Then it sends a response with a rewritten header, forcing the client to store the resource in the cache after 10 seconds.

or..

2) Nginx first overwrites the response headers and then interprets them. It stores the resource after 10 seconds and sends a response to the client, which also caches it after 10 seconds.

+4
source share
1 answer

Nginx adds its header directly in front of the source server, so you will have:

cache-control: public, max-age=10 cache-control: public, max-age=60 

and the source header will replace the nginx header.

Decision? Use nginx v1.4.3, which has the more_set_headers and more_clear_headers module, to replace or clear headers from the source.

You can download the module from here .
Here is how to download nginx 1.4.3 and how to install it.
Here 's how to use the directives.

+7
source

All Articles