Configuring expires
##expires plays the role of controlling page caching, reasonable configuration Expires can reduce many server requests. To configure expires, you can add it to the http segment or the server segment or the location segment.
location ~ \.(gif|jpg|jpeg|png|bmp|ico)$ { root /var/www/img/; expires 30d; }
For example, the
location ~ \.(wma|wmv|asf|mp3|mmf|zip|rar|swf|flv)$ { root /var/www/upload/; expires max; }
time: You can use positive or negative numbers. The value of the "Expires" header will be set by adding the current system time to the set time value.
The time value also controls the value of "Cache-Control":
Negative number means no-cache
Positive number or zero means max-age=time
max: Specify the value of "Expires" as 31 December2037 23:59:59GMT, and the value of "Cache-Control" as 10 years.
-1: Specify the value of "Expires" as the current server time -1s, which means it will expire forever.
off: Do not modify the values of "Expires" and "Cache-Control"
Cache-Control uses the max-age directive to specify how long the component will be cached.
For browsers that do not support http1.1, expires still need to be controlled. So it's best to specify two response headers. But the HTTP specification stipulates that the max-age directive will rewrite the expires header.
Nginx usage tutorial column to learn!
The above is the detailed content of How to configure the expires function of nginx. For more information, please follow other related articles on the PHP Chinese website!