国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 網(wǎng)站 > Apache > 正文

在Apache服務(wù)器上啟用GZip壓縮靜態(tài)內(nèi)容的方法

2024-08-27 18:23:40
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
這篇文章主要介紹了在Apache服務(wù)器上啟用GZip壓縮靜態(tài)內(nèi)容的方法,通過(guò)配置.htaccess文件即可輕松實(shí)現(xiàn),同時(shí)附帶了一些GZip的常用命令,需要的朋友可以參考下

為了優(yōu)化網(wǎng)站的訪問速度,我們可以通過(guò)對(duì)靜態(tài)內(nèi)容進(jìn)行壓縮,從而減少網(wǎng)頁(yè)加載的時(shí)間,大大節(jié)省用戶的帶寬。在這篇文章中,我將介紹如何使用Apache和.htaccess文件進(jìn)行靜態(tài)內(nèi)容壓縮。

首先讓我介紹一下,我們可以使用兩種不同的方法壓縮內(nèi)容:GZip 和 deflate。

介紹

GZip方法在早期的apache版本中使用(在Apache 1.3之前)。但在那之后apache引入了deflate方法,相比GZip并沒有太大的效果(但仍是非常好的)。然而,GZip在apache 1.3之后不再提供更多的支持。因此,你的Apache版本必須大于1.3,如果沒有,你必須升級(jí)到最新版本的Apache。

在使用壓縮之前,你必須啟用apache的mod_deflate模塊。要啟用這個(gè)模塊,你只需要從httpd.conf文件去掉這個(gè)模塊行。

啟用這個(gè)模塊后,你的服務(wù)器準(zhǔn)備好提供壓縮的內(nèi)容。但是,服務(wù)器只有當(dāng)它接收到來(lái)自客戶端的相應(yīng)頭文件時(shí),才會(huì)創(chuàng)建壓縮內(nèi)容。所以,現(xiàn)在你需要將下面的代碼放置到你網(wǎng)站的htaccess文件,才能通知服務(wù)器提供壓縮的內(nèi)容。

.HTACCESS代碼

<ifmodule mod_deflate.c=""> # force deflate for mangled headers # developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/ <ifmodule mod_setenvif.c=""> <ifmodule mod_headers.c="">  SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)/s*,?/s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding  RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding </ifmodule> </ifmodule>  # HTML, TXT, CSS, JavaScript, JSON, XML, HTC: <ifmodule filter_module=""> FilterDeclare COMPRESS FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css FilterProvider COMPRESS DEFLATE resp=Content-Type $text/plain FilterProvider COMPRESS DEFLATE resp=Content-Type $text/xml FilterProvider COMPRESS DEFLATE resp=Content-Type $text/x-component FilterProvider COMPRESS DEFLATE resp=Content-Type $application/javascript FilterProvider COMPRESS DEFLATE resp=Content-Type $application/json FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xml FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xhtml+xml FilterProvider COMPRESS DEFLATE resp=Content-Type $application/rss+xml FilterProvider COMPRESS DEFLATE resp=Content-Type $application/atom+xml FilterProvider COMPRESS DEFLATE resp=Content-Type $application/vnd.ms-fontobject FilterProvider COMPRESS DEFLATE resp=Content-Type $image/svg+xml FilterProvider COMPRESS DEFLATE resp=Content-Type $application/x-font-ttf FilterProvider COMPRESS DEFLATE resp=Content-Type $font/opentype FilterChain  COMPRESS FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no </ifmodule>  <ifmodule !mod_filter.c=""> # Legacy versions of Apache AddOutputFilterByType DEFLATE text/html text/plain text/css application/json AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE text/xml application/xml text/x-component AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml  AddOutputFilterByType DEFLATE application/atom+xml AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject  AddOutputFilterByType DEFLATE application/x-font-ttf font/opentype </ifmodule></ifmodule>
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 红安县| 邮箱| 珠海市| 淮安市| 磐石市| 铁力市| 湘潭市| 南木林县| 原阳县| 城口县| 谢通门县| 永丰县| 洛宁县| 郑州市| 岑溪市| 曲松县| 阿坝| 南川市| 夏河县| 萍乡市| 稷山县| 仁化县| 元阳县| 四子王旗| 依兰县| 沈丘县| 临澧县| 湘乡市| 盘山县| 柘荣县| 绍兴市| 双辽市| 中卫市| 青川县| 长岛县| 博乐市| 会同县| 郴州市| 湛江市| 东乡县| 高淳县|