How to enable or disable nginx cache

王林
Release: 2020-12-25 10:42:59
forward
5104 people have browsed it

How to enable or disable nginx cache

Sometimes when we are debugging the website program, we will encounter the problem that the code modification is invalid due to the browser's cache. At this time, we must force refresh to clear the cache, which is very of inconvenience.

(Learning video sharing: Programming video)

If we disable nginx cache, let the browser go to the server to request the file every time instead of reading it in the browser It will be much more convenient to retrieve the cached files.

After the program is debugged and goes online, you can turn on nginx cache to save the server's bandwidth traffic, reduce some requests, and reduce the pressure on the server.

Achieve the switch effect by configuring the nginx configuration file /usr/local/nginx/conf/nginx.conf

1. Enable cache

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {  
    #设置缓存上面定义的后缀文件缓存到浏览器的生存时间
  expires   3d;
}
Copy after login

2. Disable Cache

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ { 
    #禁止缓存,每次都从服务器请求
  add_header Cache-Control no-store;
}
Copy after login

Related recommendations:nginx tutorial

The above is the detailed content of How to enable or disable nginx cache. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!