Home>Article>Operation and Maintenance> How to configure the expires function of nginx
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; }Control the expiration time of pictures, etc. to 30 days. Of course, this time Can be set longer. It depends on the situation.
For example, the
location ~ \.(wma|wmv|asf|mp3|mmf|zip|rar|swf|flv)$ { root /var/www/upload/; expires max; }expires directive can control the "Expires" and "Cache-Control" headers in the HTTP response (functioning to control the page The role of caching)
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 tutorialcolumn 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!