最近有個客戶,因為本身頻寬不足,且也沒預算升級頻寬,但卻又不斷反應網站延遲很高,試問該如何解決呢?
在頻寬不足時,想要有低延遲,的確很難
我想到的解決方式:
1.壓縮
2.快取
3.降低HTTP Request次數 (HTTP2.0)
4.使用CDN
5.減少DNS解析次數
以下網站可以測試網站傳輸效能,並且提出效能不足的解決方式
https://developers.google.com/speed/pagespeed/insights/
https://tools.pingdom.com/
Apache的設定
#vi /etc/http/conf.d/httpd.conf
#Cache <ifModule mod_expires.c> <Filesmatch "\.(jpg|jpeg|png|gif|js|css|swf|ico|woff|mp3)$"> ExpiresActive On ExpiresDefault "access plus 2 days" </Filesmatch> </IfModule> #Compression <IfModule mod_deflate.c> DeflateCompressionLevel 6 #AddOutputFilerByType DEFLATE 後面加上指定Content-Type檔案需要壓縮 AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-httpd-php </IfModule>
再搭配Google 推出的mod_pagespeed套件
#wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.rpm
#yum -y install at
#rpm -ivh mod-pagespeed-stable_current_x86_64.rpm
#vi /etc/httpd/conf.d/pagespeed.conf
<IfModule pagespeed_module>
# Turn on mod_pagespeed. To completely disable mod_pagespeed, you
# can set this to "off".
ModPagespeed on
# We want VHosts to inherit global configuration.
# If this is not included, they'll be independent (except for inherently
# global options), at least for backwards compatibility.
ModPagespeedInheritVHostConfig on
....以下省略....
#systemctl restart httpd