One: Nginx configure expires cache to boost website load
For pictures of the website, especially news stations, once published, the changes may be very small. We want to be able to cache the image cached on the user's browser for a long time after the user has visited it. You can use the Nginx expires setting to set the expiration time. In the location or if paragraph, to write. Format expires 30s; Expires 30m; Expires 2h; 304 Is also a good way to cache the principle is: The server response file content is, at the same time respond to the ETag label (content of the signature, the content changes, he also changed), and Last_modified_since 2 Tag Value Browser next time the request, the header information sent these two tags, The server detects that the file has not changed, such as none, the direct header information returned etag,last_modified_since the browser knows that the content has not changed, so the local cache is called directly. This process, also requests the server, but the content of the transfer is very small. For short change cycles, such as static html,js,css, more suitable for this way
-----------------------
The configuration in nginx.conf is as follows:
server{
#只对图片进行缓存
Location ~* \. (Jpg|gif|png|jpeg) {
#设置缓存为一天
Expires 1d;
}
}
----------------------
Configuring expires cache in Nginx to boost Web site load