阿帕奇-Caching:如何配置Apache中2+响应头。 [英] Apache -Caching: How to Configure Response headers in Apache 2+.

查看:153
本文介绍了阿帕奇-Caching:如何配置Apache中2+响应头。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新了Apache配置和缓存。

I am very new in Apache Configuration and caching.

我要在Apache中(例如:max-age的,最小的新鲜,最后修改等)设置一些头。

I want set some headers in Apache (eg max-age, min-fresh, last modified etc).

有检查模块在那里,那里安装并加载....

Have checked Modules are there and there installed and loaded....

已编辑httpd.conf文件并重新开始制作关于缓存头的一些变化后的相同。

Have edited httpd.conf and re-started the same after making some changes regarding caching headers.

例如

<FilesMatch "\.(ico|pdf|flv|jpe?g|png|gif|js|css|swf)$">

   ExpiresActive On

   ExpiresDefault "access plus 1 year" 
</FilesMatch>`  



Header unset ETag
FileETag None
<FilesMatch "(?i)^.*\.(ico|flv|jpg|jpeg|png|gif|js|css)$">
    Header unset Last-Modified
    Header set Expires "Fri, 21 Dec 2012 00:00:00 GMT"
    Header set Cache-Control "public, no-transform"
</FilesMatch>

甚至尝试不同的其他的东西,当我试图检查在客户端(MSIE和Mozilla)的反应。这些头都不是为了回应。

Even tried different other things and when I tried to check for response on client side (MSIE and Mozilla). None of these headers came in response.

LoadModule foo_module modules/mod_foo.so

LoadModule auth_basic_module modules/mod_auth_basic.so  
LoadModule auth_digest_module modules/mod_auth_digest.so  
LoadModule authn_file_module modules/mod_authn_file.so  
LoadModule include_module modules/mod_include.so  
LoadModule log_config_module modules/mod_log_config.so  
LoadModule logio_module modules/mod_logio.so  
LoadModule env_module modules/mod_env.so  
LoadModule ext_filter_module modules/mod_ext_filter.so  
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule expires_module modules/mod_expires.so  
LoadModule headers_module modules/mod_headers.so  
LoadModule dav_module modules/mod_dav.so  
LoadModule status_module modules/mod_status.so  
LoadModule autoindex_module modules/mod_autoindex.so  
LoadModule info_module modules/mod_info.so
LoadModule dav_fs_module modules/mod_dav_fs.so  
# ......
LoadModule cache_module modules/mod_cache.so  
LoadModule suexec_module modules/mod_suexec.so  
LoadModule disk_cache_module modules/mod_disk_cache.so  
LoadModule file_cache_module modules/mod_file_cache.so  
LoadModule mem_cache_module modules/mod_mem_cache.so  
LoadModule cgi_module modules/mod_cgi.so   
and these are located on specific directory ....  
(shows the desired output -- ls /etc/httpd/modules | egrep "headers|expire")   

这些只是其中我也做了变化。请让我知道,如果我米失去了一些东西,或做错事,

These are the only changes which I have done. Please let me know if I m missing something or doing something wrong,

推荐答案

的到期可能无法工作,因为在MIME类型未设置。您的显示mime_magic_module模块/ mod_mime_magic.so为加载,但你仍然可以使用AddType再使用,而不是FilesMatch ExpiresByType。此外,你应该将Cache-Control公之前设置杂注公开。

The expires might not be working because the mime types are not set. Your showing mime_magic_module modules/mod_mime_magic.so as loaded but you could still use the AddType then use ExpiresByType instead of FilesMatch. Also you should set Pragma "public" before the Cache-Control "Public".

下面是一个防弹到期,我使用的gzip,FileEtag和高速缓存控制。它适用于大多数的Apache配置。

Here is a bullet proof expires, gzip, FileEtag and cache control that I use. It works on most Apache configurations.

<IfModule mod_mime.c>
    AddType text/css .css
    AddType application/x-javascript .js
    AddType text/html .html .htm
    AddType text/richtext .rtf .rtx
    AddType image/svg+xml .svg .svgz
    AddType text/plain .txt
    AddType text/xsd .xsd
    AddType text/xsl .xsl
    AddType text/xml .xml
    AddType video/asf .asf .asx .wax .wmv .wmx
    AddType video/avi .avi
    AddType image/bmp .bmp
    AddType application/java .class
    AddType video/divx .divx
    AddType application/msword .doc .docx
    AddType application/x-msdownload .exe
    AddType image/gif .gif
    AddType application/x-gzip .gz .gzip
    AddType image/x-icon .ico
    AddType image/jpeg .jpg .jpeg .jpe
    AddType application/vnd.ms-access .mdb
    AddType audio/midi .mid .midi
    AddType video/quicktime .mov .qt
    AddType audio/mpeg .mp3 .m4a
    AddType video/mp4 .mp4 .m4v
    AddType video/mpeg .mpeg .mpg .mpe
    AddType application/vnd.ms-project .mpp
    AddType application/vnd.oasis.opendocument.database .odb
    AddType application/vnd.oasis.opendocument.chart .odc
    AddType application/vnd.oasis.opendocument.formula .odf
    AddType application/vnd.oasis.opendocument.graphics .odg
    AddType application/vnd.oasis.opendocument.presentation .odp
    AddType application/vnd.oasis.opendocument.spreadsheet .ods
    AddType application/vnd.oasis.opendocument.text .odt
    AddType audio/ogg .ogg
    AddType application/pdf .pdf
    AddType image/png .png
    AddType application/vnd.ms-powerpoint .pot .pps .ppt .pptx
    AddType audio/x-realaudio .ra .ram
    AddType application/x-shockwave-flash .swf
    AddType application/x-tar .tar
    AddType image/tiff .tif .tiff
    AddType audio/wav .wav
    AddType audio/wma .wma
    AddType application/vnd.ms-write .wri
    AddType application/vnd.ms-excel .xla .xls .xlsx .xlt .xlw
    AddType application/zip .zip
</IfModule>
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css A31536000
    ExpiresByType application/x-javascript A31536000
    ExpiresByType text/html A3600
    ExpiresByType text/richtext A3600
    ExpiresByType image/svg+xml A3600
    ExpiresByType text/plain A3600
    ExpiresByType text/xsd A3600
    ExpiresByType text/xsl A3600
    ExpiresByType text/xml A3600
    ExpiresByType video/asf A31536000
    ExpiresByType video/avi A31536000
    ExpiresByType image/bmp A31536000
    ExpiresByType application/java A31536000
    ExpiresByType video/divx A31536000
    ExpiresByType application/msword A31536000
    ExpiresByType application/x-msdownload A31536000
    ExpiresByType image/gif A31536000
    ExpiresByType application/x-gzip A31536000
    ExpiresByType image/x-icon A31536000
    ExpiresByType image/jpeg A31536000
    ExpiresByType application/vnd.ms-access A31536000
    ExpiresByType audio/midi A31536000
    ExpiresByType video/quicktime A31536000
    ExpiresByType audio/mpeg A31536000
    ExpiresByType video/mp4 A31536000
    ExpiresByType video/mpeg A31536000
    ExpiresByType application/vnd.ms-project A31536000
    ExpiresByType application/vnd.oasis.opendocument.database A31536000
    ExpiresByType application/vnd.oasis.opendocument.chart A31536000
    ExpiresByType application/vnd.oasis.opendocument.formula A31536000
    ExpiresByType application/vnd.oasis.opendocument.graphics A31536000
    ExpiresByType application/vnd.oasis.opendocument.presentation A31536000
    ExpiresByType application/vnd.oasis.opendocument.spreadsheet A31536000
    ExpiresByType application/vnd.oasis.opendocument.text A31536000
    ExpiresByType audio/ogg A31536000
    ExpiresByType application/pdf A31536000
    ExpiresByType image/png A31536000
    ExpiresByType application/vnd.ms-powerpoint A31536000
    ExpiresByType audio/x-realaudio A31536000
    ExpiresByType application/x-shockwave-flash A31536000
    ExpiresByType application/x-tar A31536000
    ExpiresByType image/tiff A31536000
    ExpiresByType audio/wav A31536000
    ExpiresByType audio/wma A31536000
    ExpiresByType application/vnd.ms-write A31536000
    ExpiresByType application/vnd.ms-excel A31536000
    ExpiresByType application/zip A31536000
</IfModule>
<IfModule mod_deflate.c>
    <IfModule mod_setenvif.c>
        BrowserMatch ^Mozilla/4 gzip-only-text/html
        BrowserMatch ^Mozilla/4\.0[678] no-gzip
        BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
        BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
    </IfModule>
    <IfModule mod_headers.c>
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
    AddOutputFilterByType DEFLATE text/css application/x-javascript text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon
</IfModule>
<FilesMatch "\.(css|js)$">
    <IfModule mod_headers.c>
        Header set Pragma "public"
        Header set Cache-Control "public, must-revalidate, proxy-revalidate"
    </IfModule>
    FileETag MTime Size
</FilesMatch>
<FilesMatch "\.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$">
    <IfModule mod_headers.c>
        Header set Pragma "public"
        Header set Cache-Control "public, must-revalidate, proxy-revalidate"
    </IfModule>
    FileETag MTime Size
</FilesMatch>
<FilesMatch "\.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif|tiff|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$">
    <IfModule mod_headers.c>
        Header set Pragma "public"
        Header set Cache-Control "public, must-revalidate, proxy-revalidate"
    </IfModule>
    FileETag MTime Size
</FilesMatch>

这篇关于阿帕奇-Caching:如何配置Apache中2+响应头。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆