Nginx add_header and cache control Nginx add_header and cache control nginx nginx

Nginx add_header and cache control


Nginx adds its header just before the origin server, so you will have:

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

and the origin header will replace the nginx header.

The solution? Use nginx v1.4.3 that has the module more_set_headers and more_clear_headers in order to replace or clear the headers from origin.

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


If you want to totally discard the original servers header you can add:

proxy_hide_header 'Cache-Control';add_header 'Cache-Control' "public, max-age=10";

This will strip the original header and add your own.