Configuring expires cache in Nginx to boost Web site load

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.