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; }
2. Disable Cache
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ { #禁止缓存,每次都从服务器请求 add_header Cache-Control no-store; }
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!