Specify cache expire time in Apache 2.4

如果有某些檔案會經常更動(比方說一些 batch process 會將結果寫成 .html 檔),又希望每次瀏覽時能夠拿到最新的,而不是瀏覽器內的 cache,那可以在 apache2.4 內這樣設定

Alias /myfolder /var/opt/www/myfolderpath
        <Directory /var/opt/www/myfolderpath>
            Options FollowSymLinks Indexes
            DirectoryIndex index.html
            Require all granted
            AllowOverride All
                <filesMatch "\.(html)$">
                ExpiresActive on
                ExpiresDefault "access plus 10 minutes"
                Header merge Cache-Control public
                FileETag All
                </filesMatch>
        </Directory>

詳細參考以下這幾篇

  1. https://httpd.apache.org/docs/2.4/mod/mod_headers.html
  2. https://httpd.apache.org/docs/2.4/mod/mod_expires.html
  3. https://httpd.apache.org/docs/2.4/mod/mod_cache.html
  4. https://www.digitalocean.com/community/tutorials/how-to-configure-apache-content-caching-on-ubuntu-14-04