Enable gzip compression for Apache2.0x

Source: Internet
Author: User
Recently, I have no research on some Web optimizations. when I used the pagespeed tool to detect the website, I found that gzip compression has not been enabled, so I went online to find materials for an experiment. in apache2.0 or above (including apache2.0) in the version, gzip compression uses the mod_deflate module. the configuration steps are as follows... recently, I have no research on some Web optimization problems. when I used the page speed tool to check the website, I found that gzip compression has not been enabled, so I went online to find materials for an experiment;
 
The mod_deflate module is used for gzip compression in apache2.0 and later versions (including apache2.0). The configuration steps are as follows:
Step 2
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
Open httpd. after conf, remove the # sign in front of the above two configurations, so that apache will enable these two modules, where mod_deflate is the compression module, it is to perform gzip compression on the code to be transmitted to the client. the mod_headers module is used to tell the browser that the page uses gzip compression, if mod_headers is not enabled, the browser downloads the compressed gzip page and cannot display it normally.
 
Step 2
In httpd. add the following code to conf to add it to any blank space. if you are not familiar with apache, put it in http if you are worried about adding an error. the last line of the conf file, which can be written by a virtual server. put the htaccess file in the project.

SetOutputFilter DEFLATE # is required, just like a switch, to tell apache to compress the content transmitted to the browser.
 
SetEnvIfNoCase Request_URI .(? : Gif | jpe? G | png) $ no-gzip dont-vary # set to not compress gif, jpg, jpeg, and png image files with the suffix.
SetEnvIfNoCase Request_URI .(? : Exe | t? Gz | zip | bz2 | sit | rar) $ no-gzip dont-vary # Same as above, that is, the settings are incorrect for exe, tgz, gz... File for compression
SetEnvIfNoCase Request_URI .(? : Pdf | mov | avi | mp3 | mp4 | rm) $ no-gzip dont-vary
 
AddOutputFilterByType DEFLATE text/* # Set to compress the text content of the file, such as text/html text/css text/plain.
AddOutputFilterByType DEFLATE application/ms * application/vnd * application/postscript application/javascript application/x-javascript # you only need to know the application/javascript application/x-javascript section., this section indicates compressing javascript files.
AddOutputFilterByType DEFLATE application/x-httpd-php application/x-httpd-fastphp # this section tells apache to compress php files.
 
BrowserMatch ^ Mozilla/4 gzip-only-text/html # Netscape 4.x has some problems, so only the compressed file type is text/html
BrowserMatch ^ Mozilla/4.0 [678] no-gzip # Netscape 4.06-4.08 has more problems, so compression is not enabled.
BrowserMatch \ bMSIE! No-gzip! Gzip-only-text/html # IE will pretend to be Netscape, but in fact it is no problem

 
In this configuration, gzip compression in apache is configured. After apache is restarted, the new configuration will take effect.
 
Finally, I used a tool to check whether the score was improved a lot ~ Haha. However, enabling the gzip function requires additional CPU resource overhead.


From? ㄨ ┛
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.