Apache網頁優化
- Apache網頁優化
- 網頁壓縮
- 1,檢查是否安裝mod_deflate模塊
- 2,如果沒有安裝mod_deflate模塊,重新編譯安裝Apache添加mod_deflate模塊
- 3,配置 mod_deflate 模塊啟用
- 4,檢查安裝情況,啟動服務
- 5,測驗 mod_deflate 壓縮是否生效
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"





轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/246510.html
標籤:其他
下一篇:游戲安全:服務端SQL安全方案。
