Browser cache is used to accelerate browsing and save network resources. The browser stores recently requested documents on the user's disk.
Nginx can use the expires command to set the browser header.
Syntax: expires [time | epoch | max | Off]
Default Value: expires off
Scope: HTTP, server, location
This command can be used to control the header labels of "expires" and "cache-control" in the HTTP Response (to control the page cache ).
You can use a positive or negative number in the time value. The value of the "expires" header is obtained by the current system time plus the time value you set.
Epoch specifies that the value of "expires" is 1 January, 1970, 00:00:01 GMT.
Max specifies that the value of "expires" is 31 December 2037 23:59:59 GMT, and the value of "cache-control" is 10 years.
-1 specify the value of "expires" as the current server time-1 s, that is, permanently expired
Example:
Image cache for 30 days
Location ~. * \. (JPG | PNG | JPEG) $
{
Expires 30d;
}
Javascript CSS cache for one hour
Location ~. * \. (JS | CSS )? $
{
Expires 1 h;
}