Configure your servers to send cache headers
We will explain how to configure servers to send cache headers in Apache and Nginx.
Apache
To configure cache headers in Apache, we can use two modules: mod_expires and mod_header.
mod_expires
This module allows us to manipulate the HTTP Expires header and the server's max-age directive. We can set the expiration date for cached resources. This module can be applied in the following contexts: server config, virtual host, directory, .htaccess.
Configuration example:
For more information about mod_expires, click here.
mod_headers
It provides directives that allow us to have control over the response headers. We can replace, merge, or remove the headers of our website. This module can be applied in the following contexts: server config, virtual host, directory, and .htaccess.
Configuration example:
For more information about mod_expires, click here.
Ngninx
To configure cache headers in Nginx, we will use the ngx_http_headers_module.
This module allows us to add "Expires" and "Cache-Control" directives to a response header. We can apply it in the following contexts: http, server, location, and if in location.
Configuration example:
Last updated