How to do nginx php without caching files?

05-16-2024

Settings for nginx php not to cache files: 1. Find and open the configuration file of nginx; 2. via location ~. * \. (gif | jpg | JPEG | png | BMP | swf | js | CSS) $ {add _ headercache-controlno-store; } way to prohibit caching.

Php introduction to employment online live class: enter the learning API post = postman+swagger+mock+jmeter super easy-to-use API debugging tool: click to use.

Operating environment of this tutorial: windows7 system, PHP version 8.1 and Dell G3 computer.

What if nginx php doesn't cache files?

Nginx disables the configuration of cache.

When debugging the website program, we often encounter the cache problem of the browser, which makes the modified front-end code ineffective. The cache can only be cleared after each forced refresh through Ctrl+F5. At this time, if nginx cache is disabled, it can reduce some minor troubles and make the browser go to the server to request files every time instead of reading cached files in the browser.

When the program is debugged and online, nginx cache can be opened, which can save the bandwidth flow of the server, reduce some requests and reduce the pressure on the server.

By configuring nginx's configuration file/usr/local/Nginx/conf/Nginx.conf, the switching effect can be achieved.

1. Enable caching

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ { # Set the lifetime of caching the suffix file defined above to the browser. expires 3d; }

2. Disable caching

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ { # No caching, always request from the server. add_header Cache-Control no-store; }

Recommended study: PHP video tutorial

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us