Home > Backend Development > PHP Tutorial > Don't let CDN cache your dynamic files

Don't let CDN cache your dynamic files

WBOY
Release: 2016-07-28 08:27:35
Original
1473 people have browsed it

It’s like this: We have a domain name here that is on CDN, which originally cached some static resources such as IMG and JS. But due to business needs, we added a new dynamic php file as an interface to accept some user feedback.
Then today there was a small problem with this interface online. I went to debug and found that refreshing did not work after I changed the code, but the code worked when I changed the parameters of the link. At that time, I suspected that the link was cached by the CDN. But the operation and maintenance told me that CDN will not cache dynamic files. Then I went to test the nginx log and refreshed the web page. There was indeed no access log.
Finally, the operation and maintenance sent the link to the CDN vendor for analysis, and found that it was indeed cached. The CDN is configured to follow the policy of the origin site. By default, we have not set the PHP file not to be cached, so it caches it for us for 24 hours
If you configure PHP not to cache, we need to add header to the nginx configuration file location

<code><span>//配置PHP不缓存</span>
location ~ <span>.</span><span>*\</span><span>.</span>(php<span>|</span>php5)<span>?</span>$ {
        add_header <span>Cache</span><span>-Control</span> no<span>-cache</span>;

    }
<span>//配置缓存2分钟</span>
location ~<span>*</span> ^<span>.</span><span>+\</span><span>.</span>(js<span>|</span>css)$ {
        expires <span>120</span>s;
    }</code>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced the content of Do not let your dynamic files be cached by CDN, including aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

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