In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "how to set up Nginx cache". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
When developing and debugging web, you often encounter the trouble of emptying the cache or forcing refresh to test because of the browser cache (cache). Provide the settings of apache non-cache configuration and nginx non-cache configuration. There are two common cache settings, both using add_header: Cache-Control and Pragma, respectively.
Nginx:location ~. *\. (css | js | swf | php | htm | html) ${add_header Cache-Control no-store;add_header Pragma no-cache;}
For the static content in the site that is not often modified (such as pictures, JS,CSS), you can set the expires expiration time in the server and control the browser cache to effectively reduce the bandwidth traffic and reduce the pressure on the server.
Take the Nginx server as an example:
Location ~. *\. (gif | jpg | jpeg | png | bmp | swf) ${# Expiration time is 30 days. # Image files are not updated. The expiration date can be set to a larger value. If updated frequently, it can be set to a smaller value. Expires 30d;} location ~. *\. (js | css) ${expires 10d;}
[background]: Expires is the response header field of the Web server, which tells the browser that the browser can cache data directly from the browser before the expiration time in response to the http request without having to request it again.
[related information]
1. Cache-control strategy
The role of Cache-Control is the same as that of Expires, which indicates the validity period of the current resource and controls whether the browser caches the data directly from the browser or resends the request to the server to retrieve the data. It's just that Cache-Control has more choices and more detailed settings, and if you set it at the same time, it has a higher priority than Expires.
Http protocol header Cache-Control:
Values can be public, private, no-cache, no- store, no-transform, must-revalidate, proxy-revalidate, max-age
The instructions in each message are as follows:
Public indicates that the response can be cached by any cache.
Private indicates that all or part of a response message for a single user cannot be processed by a shared cache. This allows the server to describe only part of the response message of the user, which is not valid for requests from other users.
No-cache indicates that request or response messages cannot be cached
No-store is used to prevent important information from being inadvertently published. Sending in a request message causes both the request and response messages to be cached.
Max-age instructs the client to receive responses whose lifetime is not longer than the specified time (in seconds).
Min-fresh instructs the client to receive responses whose response time is less than the current time plus the specified time.
Max-stale instructs the client to receive response messages that exceed the timeout period. If you specify the value of the max-stale message, the client can receive a response message that exceeds the specified value of the timeout period.
Last-Modified/If-Modified-Since
Last-Modified/If-Modified-Since should be used with Cache-Control.
Last-Modified: indicates the last modification time of this response resource. When responding to a request, the web server tells the browser when the resource was last modified.
If-Modified-Since: when the resource expires (using the max-age identified by Cache-Control), if you find that the resource has a Last-Modified declaration, you will request the web server again with the header If-Modified-Since, indicating the request time. After receiving the request, the web server finds that the header If-Modified-Since is compared with the last modification time of the requested resource. If the last modification time is relatively new, indicating that the resource has been changed again, then respond to the whole piece of resource content (written in the response message package), HTTP 200; if the last modification time is old, indicating that the resource has no new modification, then respond to HTTP 304( no packet body, save browsing), and tell the browser to continue to use the saved cache.
In the end, it is equivalent to setting up these three types of html caching technologies:
This is the end of the content of "how to set up Nginx cache". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.