Apache網頁優化實用技巧

Apache網頁優化

  • 前言:在企業中,部署Apache後只採用默認的配置參數,引發網站很多問題,換言之默認配置是針對以前較低的服務器配置的,隨着互聯網時代的發展,之前的默認配置已經不適用於現在了。

網頁壓縮

1,檢查是否安裝mod_deflate模塊

apachectl -t -D DUMP_MODULES | grep "deflate"

在這裏插入圖片描述

2,如果沒有安裝mod_deflate模塊,重新編譯安裝Apache添加mod_deflate模塊

systemctl stop httpd.service
cd /usr/local/httpd/conf/
mv httpd.conf httpd.conf.bak

在這裏插入圖片描述

yum -y install gcc gcc-c++ pcre pcre-devel zlib-devel

在這裏插入圖片描述

cd /opt/httpd-2.4.29/
./configure \
--prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi \
--enable-deflate               #加入mod_deflate模塊

在這裏插入圖片描述

make -j 4 && make install

在這裏插入圖片描述

3,配置 mod_deflate 模塊啓用

vim /usr/local/httpd/conf/httpd.conf
--52行--修改
Listen 192.168.199.10:80
--105行--取消註釋
LoadModule deflate_module modules/mod_deflate.so      #開啓mod_deflate模塊
--199行--取消註釋,修改
ServerName www.muzi.com:80
--末行添加--
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript text/jpg text/png
#代表對哪些內容啓用gzip壓縮
DeflateCompressionLevel 9     #代表壓縮級別,範圍爲1~9
SetOutputFilter DEFLATE       #代表啓用deflate模塊對本站點的輸出進行gzip壓縮
</IfModule>

在這裏插入圖片描述

在這裏插入圖片描述

在這裏插入圖片描述

在這裏插入圖片描述
在這裏插入圖片描述

4,檢查安裝情況,啓動服務

apachectl -t       #驗證配置文件的配置是否正確   httpd -t  是一樣的效果
apachectl -t -D DUMP_MODULES | grep "deflate"  #檢查mod_deflate模塊是否以安裝
   deflate_module (shared)        #已安裝的正確結果

systemctl start httpd.service

在這裏插入圖片描述
在這裏插入圖片描述

5,測試 mod_deflate 壓縮是否生效

cd /usr/local/httpd/htdocs
先將music.jpg文件傳到/usr/local/httpd/htdocs目錄下
vim index.html
<html><body><hl>I opened my eyes last night and saw you in the low light.
Walking down by the bay, on the shore,staring up at the planes that aren't there anymore
I was feeling the night grow old and you were looking so cold
Like an introvert, I drew my over shirt.Around my arms and began to shiver violently before
You happened to look and see the tunnels all around me.Running into the dark underground</hl>
<img src="music.jpg"/>
</body></html>

在這裏插入圖片描述
在這裏插入圖片描述

方法一:
在Linux系統中,打開火狐瀏覽器,右擊點查看元素
選擇 網絡 ---> 選擇 HTML,WS,其他
訪問 http://192.168.199.10 , 雙擊200響應消息查看響應頭中包含 Content-Encoding:"gzip"

方法二
在Windows系統中依次安裝Microsoft,NET4和fiddler軟件,打開fiddler 軟件
選擇 inspectors ---> 選擇 Headers
瀏覽器訪問 http://192.168.199.10, 雙擊200響應消息查看Content-Encoding:"gzip"

在這裏插入圖片描述

在這裏插入圖片描述

在這裏插入圖片描述

在這裏插入圖片描述

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章