開啟nginx的gzip壓縮,網(wǎng)頁中的js,css等靜態(tài)資源的大小會大大的減少從而節(jié)約大量的帶寬,提高傳輸效率,給用戶快的體驗。
創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供黎川網(wǎng)站建設、黎川做網(wǎng)站、黎川網(wǎng)站設計、黎川網(wǎng)站制作等企業(yè)網(wǎng)站建設、網(wǎng)頁設計與制作、黎川企業(yè)網(wǎng)站模板建站服務,十載黎川做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡服務。
nginx實現(xiàn)資源壓縮的原理是通過默認集成的ngx_http_gzip_module
模塊攔截請求,并對需要做gzip的類型做gzip,使用非常簡單直接開啟,設置選項即可。。
gzip生效后的請求頭和響應頭
Request Headers: Accept-Encoding:gzip,deflate,sdch Response Headers: Content-Encoding:gzip Cache-Control:max-age240
從http協(xié)議的角度看,請求頭聲明acceopt-encoding:gzip deflate sdch(是指壓縮算法,其中sdch是google自己家推的一種壓縮方式)
服務器-〉回應-〉把內(nèi)容用gzip壓縮-〉發(fā)送給瀏覽器-》瀏覽器解碼gzip->接收gzip壓縮內(nèi)容
gzip的常用配置參數(shù)
靜態(tài)頁面index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>演示nginx做gzip壓縮</title> <script src="./jquery.js" ></script> </head> <body> <img src="./nginx_img.jpeg" /> <h2>nginx實現(xiàn)gzip壓縮,減少帶寬的占用,同時提升網(wǎng)站速度</h2> <h2>nginx實現(xiàn)gzip壓縮,減少帶寬的占用,同時提升網(wǎng)站速度</h2> <h2>nginx實現(xiàn)gzip壓縮,減少帶寬的占用,同時提升網(wǎng)站速度</h2> <h2>nginx實現(xiàn)gzip壓縮,減少帶寬的占用,同時提升網(wǎng)站速度</h2> <h2>nginx實現(xiàn)gzip壓縮,減少帶寬的占用,同時提升網(wǎng)站速度</h2> <h2>nginx實現(xiàn)gzip壓縮,減少帶寬的占用,同時提升網(wǎng)站速度</h2> </body> </html>
nginx的配置
server{ listen 80; server_name localhost 192.168.0.96; gzip on; gzip_buffers 32 4k; gzip_comp_level 6; gzip_min_length 200; gzip_types application/javascript application/x-javascript text/javascript text/xml text/css; gzip_vary off; root /Users/lidong/Desktop/wwwroot/test; index index.php index.html index.htm; access_log /Users/lidong/wwwlogs/access.log; error_log /Users/lidong/wwwlogs/error.log; location ~ [^/]\.php(/|$) { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
為使用gzip前的頁面請求:
開啟了gzip頁面的請求:
注意
總結
以上所述是小編給大家介紹的nginx中gzip壓縮提升網(wǎng)站速度的實現(xiàn)方法,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復大家的!
網(wǎng)頁題目:nginx中gzip壓縮提升網(wǎng)站速度的實現(xiàn)方法
URL鏈接:http://chinadenli.net/article48/ihdsep.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、手機網(wǎng)站建設、靜態(tài)網(wǎng)站、微信小程序、自適應網(wǎng)站、外貿(mào)網(wǎng)站建設
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)