压缩文件:
编辑apache模块
vim /etc/httpd/conf.modules.d/00-base.conf
确保以下三个模块没有被注释
LoadModule headers_module modules/mod_headers.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule filter_module modules/mod_filter.so
注意:也可以把三个模块放到/etc/httpd/conf/httpd.conf文件里,模块只能在一个文件中加载
设置压缩规则
vim /etc/httpd/conf/httpd.conf
末尾添加
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
# Remove browser bugs (only needed for really old browsers)
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 .("\.(ico|jpg|jpeg|png|gif|js|css)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>
<FilesMatch "\.(html|txt|htm|php)$">
Header set Cache-Control "max-age=2592000, public, must-revalidate"
</FilesMatch>
注意:max-age为缓存时间,单位秒,按需修改
第三种缓存方式
vim /etc/httpd/conf/httpd.conf
添加以下内容
<IfModule expires_module>
ExpiresActive On
#css文件缓存2592000/3600/24=1月
ExpiresByType text/css A2592000
#js文件缓存2592000/3600/24=1月
ExpiresByType application/x-javascript A2592000
ExpiresByType application/javascript A2592000
#html文件缓存2592000/3600/24=1月
ExpiresByType text/html A2592000
#图片文件缓存2592000/3600/24=1月
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/ico A2592000
ExpiresByType image/x-icon A2592000
#文件默认缓存1月
ExpiresDefault "access plus 30 days"
</IfModule>
注意:以上方式,三选一
重启apache服务
service httpd restart
注意:apache设置压缩和缓存都会增加服务器的内存压力,但设置压缩和缓存之后,网站的访问速度会有所提高
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 孟庭苇《情人的眼泪》开盘母带[低速原抓WAV+CUE]
- 孙露《谁为我停留HQCD》[低速原抓WAV+CUE][1.1G]
- 孙悦《时光音乐会》纯银CD[低速原抓WAV+CUE][1.1G]
- 任然《渐晚》[FLAC/分轨][72.32MB]
- 英雄联盟新英雄安蓓萨上线了吗 新英雄安蓓萨技能介绍
- 魔兽世界奥杜尔竞速赛什么时候开启 奥杜尔竞速赛开启时间介绍
- 无畏契约CGRS准星代码多少 CGRS准星代码分享一览
- 张靓颖.2012-倾听【少城时代】【WAV+CUE】
- 游鸿明.1999-五月的雪【大宇国际】【WAV+CUE】
- 曹方.2005-遇见我【钛友文化】【WAV+CUE】
- Unity6引擎上线:稳定性提升、CPU性能最高提升4倍
- 人皇Sky今日举行婚礼!电竞传奇步入新篇章
- 国风与电竞的奇妙邂逅 “电竞北京2024·国风电竞奇妙夜”引领文化新潮流
- 群星《辉煌滚石30男人篇》开盘母带[低速原抓WAV+CUE]
- 群星《藏迷情歌》紫银合金AQCD[低速原抓WAV+CUE]