20130419 apache mod_expires an example - plembo/onemoretech GitHub Wiki
title: Apache mod_expires: an example link: https://onemoretech.wordpress.com/2013/04/19/apache-mod_expires-an-example/ author: phil2nc description: post_id: 4675 created: 2013/04/19 14:58:32 created_gmt: 2013/04/19 18:58:32 comment_status: closed post_name: apache-mod_expires-an-example status: publish post_type: post
Apache mod_expires: an example
Good examples of server configurations are sometimes hard to find. Following is an implementation of mod_expires for a heavily trafficked, graphics intensive site. First, the config for mod_expires. In this case in a file named /etc/httpd/conf.d/expires.conf:
# mod_expires enabled
ExpiresActive on
ExpiresByType text/javascript "access plus 1 hour"
ExpiresByType application/x-javascript "access plus 1 hour"
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 7 days"
ExpiresByType image/gif "access plus 7 days"
ExpiresByType image/jpeg "access plus 7 days"
ExpiresByType image/png "access plus 7 days"
ExpiresByType text/css "access plus 7 days"
ExpiresByType text/javascript "access plus 7 days"
ExpiresByType application/x-javascript "access plus 7 days"
ExpiresByType text/xml "access plus 7 days"
ExpiresByType application/json "now"
Here's the companion mod_deflate configuration for the same site (in the file /etc/httpd/conf.d/deflate.conf):
# Configuration for mod_deflate
# If using Apache virtual hosts, read in to each vhost configuration with an
# Include statement, like "Include conf.d/deflate.conf".
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE text/json
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI .(?:gif|jp?g|png)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
DeflateFilterNote Input inputstream
DeflateFilterNote Output outputstream
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{outputstream}n/%{inputstream}n (%{ratio}n%%)' deflate
CustomLog logs/deflate_log deflate
DeflateBufferSize 8096
DeflateCompressionLevel 9
DeflateMemLevel 9
DeflateWindowSize 15
Copyright 2004-2019 Phil Lembo