How to do nginx php without caching files

藏色散人
Release: 2023-03-17 07:14:01
Original
2103 people have browsed it

How to set up nginx php not to cache files: 1. Find and open the nginx configuration file; 2. Pass "location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js| css)${add_header Cache-Control no-store;}" to disable caching.

How to do nginx php without caching files

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.

nginx php How to do not cache files?

Nginx disabling cache configuration

When debugging website programs, we often encounter browser cache problems that cause the modified front-end code to have no effect. . The cache can be cleared only after forcing a refresh via Ctrl F5 each time. At this time, if you disable the nginx cache, you can reduce some minor troubles and allow the browser to request files from the server every time instead of reading cached files in the browser.

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

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to do nginx php without caching files. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template