In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "how to configure cache static files in nginx". The content is detailed, the steps are clear, and the details are handled properly. I hope this "how to configure cache static files in nginx" article can help you solve your doubts.
1. Preparatory matters
I think you need a working nginx software: install nginx,php 7 and mysql 5.7 (lemp) on ubuntu 16.04lts.
2 configure nginx
You can refer to the expires instruction manual to set the expiration time of the http header, which can be placed in statement blocks such as http {}, server {}, location {} or conditional statements in location {} statements. You will generally use the expires instruction to control your static file in the location statement block, like the following:
Location ~ *\. (jpg | jpeg | png | gif | ico | css | js) ${expires 365d;}
In the above example, all files with suffixes of .jpg, .jpeg, .png, .gif, .ico, .css, and .js expire 365 days after the browser accesses the file. So you need to make sure that the location {} statement block contains only static files that can be cached by the browser.
Then restart the nginx process:
/ etc/init.d/nginx reload
You can use the following time settings in the expires instruction:
Off makes expires and cache-control headers unchangeable.
Epoch sets the expires header to 00:00:01 on January 1, 1970.
Max sets the expires header to 23:59:59 on December 31, 2037, and sets the maximum survival time of cache-control to 10 years.
The time without the @ prefix means that this is an expiration time related to the browser access time. If you can specify a negative time, the cache-control header will be set to no-cache. For example: expires 10d or expires 14w3d.
The time with the @ prefix specifies that it expires at a certain time of the day. The format is hh or hh:mm,h. The range is 0 to 24 m and the range is 0 to 59. For example: expires @ 15:34.
You can use the following time units:
Ms: millisecond
S: seconds
M: minutes
H: hours
D: days
W: week
M: month (30 days)
Y: year (365 days)
For example, 1h30m means one hour and thirty minutes, and 1y6m means six months of the year.
Note that if you use a header that will expire for a long time in the future, you need to change the component's file name when the component is modified. So it's a good idea to assign a version to the file. For example, if you have a javascript.js file and you want to modify it, you can add a version number after the name of the modified file. This way the browser will download the file, and if you do not change the file name, the browser will load the (old) file from the cache.
In addition to setting the expires header based on the browser access time (such as expires 10d), you can also set the benchmark of the expires header to the file modification time by using the modified keyword before the time (note that this is only valid for the actual files stored on the hard disk).
Expires modified 10d
3 Test
To test whether your configuration is valid, use the web analytics feature in Firefox's developer tool, and then use Firefox to access a static file (such as a picture). In the output header information, you should see the expires header and the cache-control header marked with max-age (the max-age tag contains a value in seconds, for example, 31536000 refers to the coming year)
After reading this, the article "how to configure cache static files in nginx" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.