1. 程式人生 > >nginx和apache設定不快取檔案

nginx和apache設定不快取檔案

在開發除錯web的時候,經常會碰到因瀏覽器快取(cache)而經常要去清空快取或者強制重新整理來測試的煩惱,提供下apache不快取配置和nginx不快取配置的設定。

apache:

首先確定配置檔案httpd.conf中確已經載入mod_headers模組。

LoadModule headers_module modules/mod_headers.so

我們可以根據檔案型別來讓瀏覽器每次都從伺服器讀取,這裡測試用css、js、swf、php、html、htm這幾種檔案。

<FilesMatch “.(css|js|swf|php|htm|html)$”>

    Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"

    Header set Pragma "no-cache"

   </FilesMatch>

nginx:

location ~ .*.(css|js|swf|php|htm|html )$ {

    add_header Cache-Control no-store;

    }