LAMP搭建11:Apache配置靜態緩衝

來源:互聯網
上載者:User

標籤:lamp   apache   搭建   配置   靜態緩衝   

在伺服器端可以配置Apache靜態緩衝,讓用戶端瀏覽器緩衝一段時間(幾個小時或幾天)該頁面中的靜態元素,如一些小圖片,樣式等等,這樣可以讓使用者每次訪問請求中不需要重複傳輸這些靜態元素,以減少每次訪問的頻寬,提高訪問速度。

1.編輯虛擬機器主機設定檔:

[[email protected] logs]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf

2.加入如下配置:指定格式檔案在瀏覽器中緩衝的時間

……

SetEnvIf Request_URI "\.jpg$" image-request

SetEnvIf Request_URI "\.png$" image-request

SetEnvIf Request_URI "\.bmp$" image-request

SetEnvIf Request_URI "\.swf$" image-request

SetEnvIf Request_URI "\.js$" image-request

SetEnvIf Request_URI "\.css$" image-request

CustomLog "| /usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/test.com-access_%Y%m%d_log 86400" combined env=!image-request

<IfModule mod_expires.c>

       ExpiresActive on

       ExpiresByType image/gif "access plus 1 days"

       ExpiresByType image/jpeg "access plus 24 hours"

       ExpiresByType image/png "access plus 24 hours"

       ExpiresByType image/css "now plus 2 hours"

       ExpiresByType application/x-javascript "now plus 2 hours"

       ExpiresByType application/x-shockwave-flash "now plus 2 hours"

       ExpiresDesfault "now plus 0 min"

   </IfModule>

<IfModule mod_rewrite.c>

……

3.檢查沒錯就重啟

[[email protected] logs]# apachectl -t

Syntax OK

[[email protected] logs]# apachectl graceful

4.使用curl命令測試一張我們網站裡的png圖片,可以看到我們上面的配置成功了,86400秒==24小時==1天:

[[email protected] logs]# curl -x127.0.0.1:80 ‘http://www.test.com/static/image/common/logo_88_31.gif‘ -I

HTTP/1.1 200 OK

Date: Wed, 11 Jan 2017 14:15:37 GMT

Server: Apache/2.2.9 (Unix) PHP/5.4.36

Last-Modified: Tue, 31 May 2016 03:08:36 GMT

ETag: "dfbad-9e0-5341ab0597500"

Accept-Ranges: bytes

Content-Length: 2528

Cache-Control: max-age=86400

Expires: Thu, 12 Jan 2017 14:15:37 GMT

Content-Type: image/gif


LAMP搭建11:Apache配置靜態緩衝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.