×ðÁú¿­Ê±¹ÙÍøµÇ¼

ÔõÑùʹÓÃNginx¾ÙÐÐHTTPÇëÇóµÄѹËõÏ¢ÕùѹËõ

ÔõÑùʹÓÃnginx¾ÙÐÐhttpÇëÇóµÄѹËõÏ¢ÕùѹËõ

NginxÊÇÒ»¿î¸ßÐÔÄܵÄWebЧÀÍÆ÷ºÍ·´ÏòÊðÀíЧÀÍÆ÷£¬Æ书ЧǿʢÇÒÎÞа¡£ÔÚ´¦ÀíHTTPÇëÇóʱ£¬¿ÉÒÔʹÓÃNginxÌṩµÄgzipºÍgunzipÄ£¿é¶ÔÇëÇó¾ÙÐÐѹËõÏ¢ÕùѹËõ£¬ÒÔ¼õСÊý¾Ý´«ÊäÁ¿£¬Ìá¸ßÇëÇóÏìÓ¦ËÙÂÊ¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃnginx¾ÙÐÐhttpÇëÇóµÄѹËõÏ¢ÕùѹËõµÄÏêϸ°ì·¨£¬²¢ÌṩÏìÓ¦µÄ´úÂëʾÀý¡£

ÉèÖÃgzipÄ£¿é

Ê×ÏÈÐèÒªÔÚNginxµÄÉèÖÃÎļþÖÐÆôÓÃgzipÄ£¿é¡£·­¿ªÄãµÄNginxÉèÖÃÎļþ£¨Í¨³£Î»ÓÚ/etc/nginx/nginx.conf»ò/usr/local/nginx/conf/nginx.conf£©£¬ÕÒµ½http¿é£¬Ìí¼ÓÒÔÏÂÉèÖãº

http {
  gzip on;
  gzip_types text/plain text/css application/javascript;
  gzip_min_length 1024;
  gzip_comp_level 1;
}

µÇ¼ºó¸´ÖÆ

ÉÏÊöÉèÖõļÄÒåÈçÏ£º

gzip on; ÌåÏÖÆôÓÃgzipÄ£¿é¡£

gzip_types ÌåÏÖÐèҪѹËõµÄÎļþÀàÐÍ¡£ÕâÀïÎÒÃÇÑ¡ÔñÁËÎı¾Îļþ¡¢CSSÎļþºÍJavaScriptÎļþ¡£Äã¿ÉÒÔƾ֤×Ô¼ºµÄÐèÇó¾ÙÐÐÉèÖá£

gzip_min_length ÌåÏÖÖ»ÓÐÎļþ³¤¶ÈÁè¼ÝÕâ¸öÖµµÄÎļþ²Å»á¾ÙÐÐѹËõ¡£

gzip_comp_level ÌåÏÖѹËõ¼¶±ð£¬¼¶±ðÔ½¸ß£¬Ñ¹ËõЧ¹ûÔ½ºÃ£¬µ«Õ¼ÓõÄCPU×ÊÔ´Ò²Ô½¶à¡£

ÉèÖÃgunzipÄ£¿é

ÈôÊÇÄãÐèÒª¶ÔÎüÊÕµ½µÄÇëÇó¾ÙÐнâѹËõ£¬»¹ÐèÒªÆôÓÃgunzipÄ£¿é¡£ÔÚͳһ¸öÉèÖÃÎļþÖÐÕÒµ½http¿é£¬Ìí¼ÓÒÔÏÂÉèÖãº

µã»÷ÏÂÔØ¡°àËÃûÌÃѹËõ¾Þ½³¡±£»

http {
  gunzip on;
}

µÇ¼ºó¸´ÖÆ

Ó¦ÓÃÉèÖò¢ÖØÆôNginx

ÉúÑÄNginxÉèÖÃÎļþºó£¬Ö´ÐÐÒÔÏÂÏÂÁîÓ¦ÓÃÉèÖò¢ÖØÆôNginxЧÀÍ£º

sudo service nginx reload

µÇ¼ºó¸´ÖÆ

ÇëÈ·±£Äã¾ß±¸×ã¹»µÄȨÏÞ¡£

Ñé֤ѹËõÏ¢ÕùѹËõ

ÏÖÔÚÄãÒѾ­ÉèÖúÃÁËNginxµÄѹËõÏ¢ÕùѹËõÄ£¿é¡£Äã¿ÉÒÔͨ¹ýÏòNginx·¢ËÍHTTPÇëÇóÀ´ÑéÖ¤ÕâЩ¹¦Ð§ÊÇ·ñÉúЧ¡£

Ê×ÏÈ£¬Ê¹ÓÃcurl¹¤¾ß·¢ËÍÒ»¸öGETÇëÇóµ½ÉèÖõÄNginxЧÀÍ£º

curl -H "Accept-Encoding: gzip, deflate" -I http://localhost

µÇ¼ºó¸´ÖÆ

ÏÂÁîÖеÄ-H “Accept-Encoding: gzip, deflate”ÌåÏÖ¸æËßЧÀÍÆ÷¿ÉÒÔ½ÓÊÜgzip»òdeflateµÄѹËõ·½·¨¡£-IÌåÏÖÖ»»ñÈ¡ÏìӦͷÐÅÏ¢£¬¶ø²»ÐèÒª»ñÈ¡ÍêÕûµÄÏìÓ¦Ìå¡£

ÈôÊÇÒ»ÇÐÕý³££¬Ä㽫»áÔÚÏìӦͷÖп´µ½ÀàËÆÏÂÃæµÄÐÅÏ¢£º

Content-Encoding: gzip

µÇ¼ºó¸´ÖÆ

ÕâÌåÏÖЧÀÍÆ÷ÒѾ­½«ÏìÓ¦ÌåѹËõ³ÉgzipÃûÌþÙÐд«Êä¡£

½ÓÏÂÀ´£¬Äã¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî·¢ËÍÒ»¸ö½âѹËõµÄÇëÇó£º

curl --compressed -I http://localhost

µÇ¼ºó¸´ÖÆ

ÏÂÁîÖеĖcompressedÌåÏÖ¸æËßЧÀÍÆ÷ÎüÊÕµ½µÄÏìÓ¦ÒѾ­±»Ñ¹Ëõ£¬ÐèÒª¾ÙÐнâѹËõ¡£

ÈôÊÇÒ»ÇÐÕý³££¬Ä㽫»áÔÚÏìӦͷÖп´µ½ÀàËÆÏÂÃæµÄÐÅÏ¢£º

Content-Encoding: 

µÇ¼ºó¸´ÖÆ

ÕâÌåÏÖЧÀÍÆ÷ÒѾ­½«ÏìÓ¦Ìå½âѹËõ£¬²¢ÒÔԭʼÃûÌþÙÐд«Êä¡£

ͨ¹ýÒÔÉϵİ취ºÍÑéÖ¤£¬ÄãÒѾ­ÀÖ³ÉÉèÖÃÁËNginxµÄgzipºÍgunzipÄ£¿é£¬ÊµÏÖÁËHTTPÇëÇóµÄѹËõÏ¢ÕùѹËõ¡£

×ܽá

±¾ÎÄÏÈÈÝÁËÔõÑùʹÓÃnginx¾ÙÐÐhttpÇëÇóµÄѹËõÏ¢ÕùѹËõ£¬²¢ÌṩÁËÏà¹ØµÄÉèÖúÍÏÂÁîʾÀý¡£Ê¹ÓÃNginxµÄgzipºÍgunzipÄ£¿éÄܹ»×ÊÖúÄã¼õСÊý¾Ý´«ÊäÁ¿£¬Ìá¸ßÇëÇóµÄÏìÓ¦ËÙÂÊ¡£Í¨¹ýºÏÀíÉèÖúÍʹÓ㬿ÉÒÔÌáÉýWebÓ¦ÓõÄÐÔÄܺÍÓû§ÌåÑé¡£ÈôÊÇÄãÔÚʹÓÃÀú³ÌÖÐÓöµ½ÎÊÌ⣬¿ÉÒԲο¼NginxµÄ¹Ù·½Îĵµ»ò×·Çó×ÊÖú¡£Ï£Íû±¾ÎÄÄÚÈݶÔÄãÓÐËù×ÊÖú£¡

²Î¿¼Á´½Ó£º

Nginx¹Ù·½Îĵµ£ºhttp://nginx.org/en/docs/

GzipÄ£¿éÉèÖÃÖ¸ÄÏ£ºhttps://nginx.org/en/docs/http/ngx_http_gzip_module.html

GunzipÄ£¿éÉèÖÃÖ¸ÄÏ£ºhttps://nginx.org/en/docs/http/ngx_http_gunzip_module.html

ÒÔÉϾÍÊÇÔõÑùʹÓÃNginx¾ÙÐÐHTTPÇëÇóµÄѹËõÏ¢ÕùѹËõµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ