You probably just want to use mod_expires, as this allow for sending of both Cache-Control header and Expires headers automatically and can allow you to specify by both access time and file modification time. It also allows you to set different defaults by file type.
Using mod_expires you could set the default expiry using the following directive:
ExpiresDefault "access plus 2 days"
Of course mod_headers is a much more general module that allows you to do some of the same stuff, but generally used more for creating custom headers or manage multiple (possibly conflicting) headers.
原文:http://stackoverflow.com/questions/12164684/mod-expires-or-mod-headers
2:一个比较全的对这个两个cache方式的配置文件。
# ##############################################################################
# # MEDIA TYPES AND CHARACTER ENCODINGS #
# ##############################################################################
# ------------------------------------------------------------------------------
# | Media types |
# ------------------------------------------------------------------------------
# Serve resources with the proper media types (formerly known as MIME types).
# http://www.iana.org/assignments/media-types/media-types.xhtml
<IfModule mod_mime.c>
# Audio
AddType audio/mp4 f4a f4b m4a
AddType audio/ogg oga ogg opus
# Data interchange
AddType application/json json map topojson
AddType application/ld+json jsonld
AddType application/vnd.geo+json geojson
# JavaScript
# Normalize to standard type.
# http://tools.ietf.org/html/rfc4329#section-7.2
AddType application/javascript js
# Manifest files
# If you are providing a web application manifest file (see the
# specification: http://w3c.github.io/manifest/), it is recommended
# that you serve it with the `application/manifest+json` media type.
#
# Because the web application manifest file doesn't have its own
# unique file extension, you can set its media type either by matching:
#
# 1) the exact location of the file (this can be done using a directive
# such as `<Location>`, but it will NOT work in the `.htaccess` file,
# so you will have to do it in the main server configuration file or
# inside of a `<VirtualHost>` container)
#
# e.g.:
#
# <Location "/.well-known/manifest.json">
# AddType application/manifest+json json
# </Location>
#
# 2) the filename (this can be problematic as you will need to ensure
# that you don't have any other file with the same name as the one
# you gave to your web application manifest file)
#
# e.g.:
#
# <Files "manifest.json">
# AddType application/manifest+json json
# </Files>
AddType application/x-web-app-manifest+json webapp
AddType text/cache-manifest appcache manifest
# Video
AddType video/mp4 f4v f4p m4v mp4
AddType video/ogg ogv
AddType video/webm webm
AddType video/x-flv flv
# Web fonts
AddType application/font-woff woff
AddType application/font-woff2 woff2
AddType application/vnd.ms-fontobject eot
# Browsers usually ignore the font media types and simply sniff
# the bytes to figure out the font type.
# http://mimesniff.spec.whatwg.org/#matching-a-font-type-pattern
# Chrome however, shows a warning if any other media types are used
# for the following two font types.
AddType application/x-font-ttf ttc ttf
AddType font/opentype otf
AddType image/svg+xml svg svgz
# Other
AddType application/octet-stream safariextz
AddType application/x-chrome-extension crx
AddType application/x-opera-extension oex
AddType application/x-xpinstall xpi
AddType application/xml atom rdf rss xml
AddType image/webp webp
AddType image/x-icon cur ico
AddType text/vtt vtt
AddType text/x-component htc
AddType text/x-vcard vcf
</IfModule>
# ------------------------------------------------------------------------------
# | Reducing MIME type security risks |
# ------------------------------------------------------------------------------
# Prevent some browsers from MIME-sniffing the response.
# This reduces exposure to drive-by download attacks and cross-origin data
# leaks, and should be left uncommented, especially if the web server is
# serving user-uploaded content or content that could potentially be treated
# as executable by the browser.
# http://www.slideshare.net/hasegawayosuke/owasp-hasegawa
# http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
# http://msdn.microsoft.com/en-us/library/ie/gg622941.aspx
# http://mimesniff.spec.whatwg.org/
<IfModule mod_headers.c>
Header set X-Content-Type-Options "nosniff"
</IfModule>
# ------------------------------------------------------------------------------
# | ETags |
# ------------------------------------------------------------------------------
# Remove `ETags` as resources are sent with far-future expires headers.
# https://developer.yahoo.com/performance/rules.html#etags
# `FileETag None` doesn't work in all cases.
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
FileETag None
# ------------------------------------------------------------------------------
# | Expires headers |
# ------------------------------------------------------------------------------
# Serve resources with far-future expires headers.
# IMPORTANT: If you don't control versioning with filename-based cache
# busting, consider lowering the cache times to something like one week.
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 year"
# Data interchange
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/ld+json "access plus 0 seconds"
ExpiresByType application/vnd.geo+json "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"
# Favicon (cannot be renamed!) and cursor images
ExpiresByType image/x-icon "access plus 1 week"
# HTML components (HTCs)
ExpiresByType text/x-component "access plus 1 month"
# HTML
ExpiresByType text/html "access plus 0 seconds"
# JavaScript
ExpiresByType application/javascript "access plus 1 year"
# Manifest files
ExpiresByType application/manifest+json "access plus 1 year"
ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
ExpiresByType text/cache-manifest "access plus 0 seconds"
# Media
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
# Web feeds
ExpiresByType application/atom+xml "access plus 1 hour"
ExpiresByType application/rss+xml "access plus 1 hour"
# Web fonts
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/font-woff2 "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
</IfModule>
摘选自: http://stackoverflow.com/questions/9933012/how-to-use-mod-headers-and-mod-expires-to-cache
相关资料: http://www.askapache.com/htaccess/apache-speed-compression.html
相关推荐
LoadModule expires_module modules/mod_expires.so LoadModule headers_module modules/mod_headers.so LoadModule ident_module modules/mod_ident.so LoadModule usertrack_module modules/mod_usertrack.so ...
`mod_jk.so`是Apache的一个模块,它用于连接Apache与Tomcat应用服务器,实现负载均衡和应用级代理,这对于运行Java Web应用程序的环境至关重要。在CentOS 6.5-6.9系统上编译安装Apache 2.4并添加mod_jk.so模块的步骤...
3. **静态文件**: 对于静态文件,建议使用Apache的其他模块(如`mod_expires`, `mod_deflate`, `mod_headers`)直接处理,以减轻Django的负担。 4. **缓存策略**: 使用缓存技术,如Django的`cached_page`中间件,或...
mod_pagespeed 是由 Google 开发的一款 Apache 模块,主要用于提升 Web 页面的加载速度。该模块无需对现有网站的 CMS(内容管理系统)进行任何修改,即可实现网页加载速度的显著提升。mod_pagespeed 通过优化 HTML、...
mod_headers mod_ident mod_imagemap mod_include mod_info mod_isapi mod_ldap mod_logio mod_log_config mod_log_forensic mod_mem_cache mod_mime mod_mime_magic mod_negotiation mod_nw_ssl mod_proxy mod_...
- **mod_expires**: 设置缓存过期时间。 - **mod_headers**: 修改HTTP头部。 - **mod_include**: 处理SSI指令。 - **mod_log_config**: 自定义日志格式。 - **mod_mime**: MIME类型处理。 - **mod_negotiation**: ...
流浪灯 这是一个基于 Ubuntu 的 LAMP(Linux-Apache-MySQL)服务器环境的 Vagrant 设置。... apache2::mod_expires apache2::mod_headers apache2::mod_env apache2::mod_setenvif apache2::mod_alias apache2::m
LoadModule headers_module modules/mod_headers.so ``` 然后重启Apache服务,使改动生效。 设置适当的缓存控制策略可以显著提升网站性能,特别是对于静态资源如图片、CSS和JavaScript文件,因为这些文件通常不会...
另外,使用缓存模块如mod_cache和mod_expires,可以减少对服务器资源的消耗。 六、日志记录 Apache服务器可以记录详细的访问日志,包括客户端IP、请求时间、请求方法、请求URL、状态码等信息。这些日志对于分析网站...
- 使用mod_expires和mod_headers设置资源过期策略,提高客户端缓存效率。 - mod_deflate用于压缩响应内容,减少网络传输量。 8. **安全性和SSL**: - 配置HTTPS支持,使用SSL/TLS证书进行加密通信。 - 安全最佳...
- 使用mod_expires和mod_headers控制缓存策略,减少不必要的服务器负载。 总之,Apache 2.2的安装和配置是一个涉及多个层面的过程,涵盖操作系统兼容性、安全性、性能优化等多个方面。遇到问题时,参考“附加安装...
- 性能优化,包括开启HTTP/1.1持久连接(mod_headers),配置合适的KeepAliveTimeout,使用mod_expires缓存静态内容,以及合理分配系统资源。 6. **错误日志和访问日志** - Apache2.2.29会生成错误日志和访问日志...
它还允许重现apache mod_expires的行为,以定义资源的有效期。 配置 静态配置( traefik.yml ) pilot : token : [REDACTED] experimental : plugins : traefik-plugin-header : moduleName : github....
7. 进入解压后的目录并执行 `./configure` 命令,配置安装路径和其他选项,例如启用mod_deflate、mod_expires、mod_headers、mod_rewrite等模块。 8. 执行 `make` 和 `make install` 来编译并安装Apache。 9. 安装...
启用 mod_headers mod_expires 已启用 启用 mod_rewrite PHP >= 5.3.6 带 PDO MySQL >= 14.14 配置 ScrollsAcademy 只能在网站或子域的根目录中运行。 将此存储your_installation_directory/public_html到您的...
Apache的缓存可以通过`mod_expires`和`mod_headers`模块实现。 启用`mod_expires`模块,确保在`/etc/httpd/conf.modules.d/00-base.conf`中`LoadModule expires_module modules/mod_expires.so`未被注释。然后,在`...
3. **缓存机制**: 利用mod_expires和mod_headers模块设置资源的过期时间,让浏览器缓存静态资源,降低服务器压力。 4. **合并CSS和JavaScript**: 减少HTTP请求次数,通过CSS Sprites或JavaScript打包工具整合多个...
2. **`LoadModule expires_module modules/mod_expires.so`**: 控制文件缓存在客户端的有效期。 3. **`LoadModule deflate_module modules/mod_deflate.so`**: 提供文件压缩功能,减少数据传输量。 4. **`LoadModule...
BlizzCMS Plus是BlizzCMS v1的重组和改进版本。 WoW-CMS的开发人员经常在封闭源代码中进行此版本的开发,同时考虑到...)Apache模块mod_headers-mod_rewrite-mod_expires PHP扩展curl-gd2-mbstring-mysqli-openssl-因此
9. **模块扩展**:Apache的核心功能可以通过加载不同的模块来扩展,如mod_deflate用于内容压缩,mod_expires处理资源过期,mod_headers控制响应头等。 10. **配置灵活性**:Apache的配置文件(通常为httpd.conf)...