Apache下的網(wǎng)站加速的方法
2015-10-10 17:10:16
12374
相信有很多做網(wǎng)站的朋友都在為自己的主機(jī),VPS而頭疼,總是會(huì)覺得速度慢,但是想要速度快的話又得花費(fèi)過大,怎么樣才能讓網(wǎng)站速度快,又經(jīng)濟(jì)呢。
今天這里分享一下在Apche下通用的一些加速技巧
一、緩存一下不常修改的文件
在.htaccess文件中添加以下語句:
其中:text/css之類代表文件類型,A2592000表示在瀏覽器中的緩存時(shí)間,2592000秒=30天
記得谷歌有個(gè)網(wǎng)站速度評級,在其中對瀏覽器的緩存時(shí)間也是其中一項(xiàng),很多人不知道怎么做,下面的就是Apahce下的做法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A600
ExpiresByType
image/x-iconA2592000
ExpiresByType application/x-javascript
A2592000
ExpiresByType text/cssA604800
ExpiresByType image/gif
A2592000
ExpiresByType image/pngA2592000
ExpiresByType image/jpeg
A2592000
ExpiresByType text/plainA86400
ExpiresByType
application/x-shockwave-flashA2592000
ExpiresByType video/x-flv
A2592000
ExpiresByType application/pdfA2592000
ExpiresByType text/html
A600
</IfModule>
|
二、開啟Gzip壓縮
這個(gè)是節(jié)省流量和提高速度所必須的。在.htaccess文件中添加以下語句:
1
2
3
4
|
<ifmodule mod_deflate.c>
AddOutputFilter
DEFLATE html xml php js css
</ifmodule>
|
三、關(guān)閉ETag
如果沒有使用ETag提供的靈活的驗(yàn)證模式,那么把所有的ETag都去掉會(huì)更好,只需在.htaccess文件中添加以下語句: