Locate the following two lines in the Apache configuration file, and then remove the comment # and reboot.
The code is as follows |
Copy Code |
LoadModule Deflate_module modules/mod_deflate.so LoadModule Expires_module modules/mod_expires.so |
Add the following code in the httpd.conf, you can add to any white space, do not know Apache friends, if you worry about adding the wrong place, put the last line of the http.conf file, if the virtual server can write. htaccess file, and then put it under the project.
The code is as follows |
Copy Code |
<ifmodule mod_deflate.c> Setoutputfilter DEFLATE #必须的, like a switch, tells Apache to compress content that is transferred to the browser Setenvifnocase Request_uri. (?: gif|jpe?g|png) $ no-gzip dont-vary #设置不对后缀gif, jpg,jpeg,png picture file for compression Setenvifnocase Request_uri. (?: Exe|t?gz|zip|bz2|sit|rar) $ no-gzip dont-vary #同上, is set not exe,tgz,gz ... The file to compress Setenvifnocase Request_uri. (?:p df|mov|avi|mp3|mp4|rm) $ no-gzip dont-vary Addoutputfilterbytype DEFLATE text/* #设置对文件是文本的内容进行压缩, such as text/html text/css Text/plain, etc. Addoutputfilterbytype DEFLATE application/ms* application/vnd* application/postscript application/javascript Application/x-javascript #这段代码你只需要了解application/javascript Application/x-javascript That's it, okay? The meaning of this paragraph is to compress the JavaScript file Addoutputfilterbytype DEFLATE application/x-httpd-php application/x-httpd-fastphp #这段是告诉apache对php类型的文件进行压缩 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 do not turn on compression Browsermatch Bmsie!no-gzip!gzip-only-text/html # IE browser will disguise as Netscape, but in fact it's not a problem </IfModule> |
This configuration to Apache in the gzip compression configuration completed, restart Apache, the new configuration will take effect
The following actions are included in the htaccess:
code is as follows |
copy code |
< Ifmodule mod_expires.c> expiresactive on expiresbytype image/gif A2592000 Expiresbytype image/jpeg A2592000 Expiresbytype image/png A2592000 expiresbytype image/x-icon A2592000 Expiresbytype application/ X-javascript A604800 Expiresbytype text/css A604800 </ifmodule> <ifmodule mod_deflate.c> Setoutputfilter DEFLATE addoutputfilterbytype DEFLATE text/html text/css image/gif image/jpeg image/png Application/x-javascript </ifmodule> |
Explain. Expiresbytype is the MIME type to set the cache time of the specific file, a is accessed, and a number after it represents the cached time after the access. Addoutputfilterbytype means to compress files based on the MIME type that follows, where gzip compression is css,html,gif,jpeg,png,javascript, etc.
Here's an article on understanding gzip compression test http://www.111cn.net/phper/apache/apache-gzip.htm
See the enabling IIS6 gzip feature below
IIS6 The gzip feature is not enabled by default, we need to manually configure it, but he did not provide a graphical configuration function, so ah, such as my technical personnel, have not considered the use of him, yesterday suddenly saw this thought, may be useful to me, but from the Internet to find, are a bunch of manual operation method, very troublesome Ah, However, the configuration file for IIS has been studied before: C: Windowssystem32inetsrvmetabase.xml, so yes, I know that as long as the function of IIS can be modified by this file to complete, so, on the file to do, according to the site provided by the changes on the Internet to search a circle, to find a similar ClickOnce Things, oh, I look for is this, all the operation of a key in place, as long as the implementation of a section of VBS or CMD configured well, hehe.
Using gzip compression increases server CPU usage but can reduce the data sent by the server to the client by compression, and if you use gzip compression IIS automatically detects when sending data to the client, if the client browser supports Ie6.0,firefox Gzip, The data is then transferred using gzip compression and, if not supported, sent in a regular manner.
Therefore, summed up his advantages and disadvantages, excellent: compressed transmission, the speed generally increased twice times. Missing: CPU usage will improve, but through my point of analysis, gzip only access to a page will be compressed, the next time if the page does not change is not compressed, unless the use of compressed dynamic files, this has to compress in real time.
Code
The code is as follows |
Copy Code |
REM Setup iiscompressionscheme for deflate cscript adsutil.vbs set w3svc/filters/compression/deflate/ Hccompressiondll "%windir%system32inetsrvgzip.dll" cscript adsutil.vbs set w3svc/filters/compression/deflate/ HcCreateFlags 0 cscript adsutil.vbs set w3svc/filters/compression/deflate/hcdodynamiccompression TRUE cscript adsutil.vbs set w3svc/filters/compression/deflate/hcdoondemandcompression TRUE cscript adsutil.vbs set W3Svc/ Filters/compression/deflate/hcdostaticcompression TRUE cscript adsutil.vbs set w3svc/filters/compression/ Deflate/hcdynamiccompressionlevel 9 cscript adsutil.vbs set w3svc/filters/compression/deflate/hcfileextensions " HTM "html" "TXT" "JS" "xml" "CSS" cscript adsutil.vbs set w3svc/filters/compression/deflate/hcondemandcomplevel 9< br> cscript adsutil.vbs set w3svc/filters/compression/deflate/hcpriority 1 cscript adsutil.vbs set w3svc/filters/ Compression/deflate/hcscriptfileextensions "ASP" DLL "EXE" ASPX "asmx" REM Setup iiscompressionscheme for GZip cscript adsutil.vbs set w3svc/filters/compression/gzip/ Hccompressiondll "%windir%system32inetsrvgzip.dll" cscript adsutil.vbs set w3svc/filters/compression/gzip/ HcCreateFlags 1 cscript adsutil.vbs set w3svc/filters/compression/gzip/hcdodynamiccompression TRUE cscript adsutil.vbs set w3svc/filters/compression/gzip/hcdoondemandcompression TRUE cscript adsutil.vbs set W3Svc/Filters /compression/gzip/hcdostaticcompression TRUE cscript adsutil.vbs set w3svc/filters/compression/gzip/ HcDynamicCompressionLevel 9 cscript adsutil.vbs set w3svc/filters/compression/gzip/hcfileextensions "htm" "html" TXT "JS" "xml" "CSS" cscript adsutil.vbs set w3svc/filters/compression/gzip/hcondemandcomplevel 9 cscript adsutil.vbs set w3svc/filters/compression/gzip/hcpriority 1 cscript adsutil.vbs set w3svc/filters/compression/ Gzip/hcscriptfileextensions "ASP" DLL "EXE" ASPX "asmx" REM Setup iiscompressionschemes Parameters cscript adsutil.vbs set W3svc/filters/compression/parameters/hccachecontrolheader max-age=86400 cscript adsutil.vbs set w3svc/filters/compression/parameters/hccompressionbuffersize 102400 cscript adsutil.vbs set w3svc/filters/compression/parameters/hccompressiondirectory "%windir%iis Temporary Compressed Files " cscript adsutil.vbs set w3svc/filters/compression/parameters/hcdodiskspacelimiting FALSE cscript adsutil.vbs set w3svc/filters/compression/parameters/hcdodynamiccompression TRUE cscript adsutil.vbs set w3svc/filters/compression/parameters/hcdoondemandcompression TRUE cscript adsutil.vbs set w3svc/filters/compression/parameters/hcdostaticcompression TRUE cscript adsutil.vbs set W3svc/filters/compression/parameters/hcexpiresheader "Wed, 1997 12:00:00 GMT" cscript adsutil.vbs set w3svc/filters/compression/parameters/hcfilesdeletedperdiskfree 256 cscript adsutil.vbs set w3svc/filters/compression/parameters/hciobuffersize 102400 cscript adsutil.vbs set w3svc/filters/compression/parameters/hcmaxdiskspaceusage 0 cscript adsutil.vbs set w3svc/filters/compression/parameters/hcmaxqueuelength 1000 cscript adsutil.vbs set W3svc/filters/compression/parameters/hcminfilesizeforcomp 1 cscript adsutil.vbs set w3svc/filters/compression/parameters/hcnocompressionforhttp10 FALSE cscript adsutil.vbs set w3svc/filters/compression/parameters/hcnocompressionforproxies FALSE cscript adsutil.vbs set W3svc/filters/compression/parameters/hcnocompressionforrange FALSE cscript adsutil.vbs set w3svc/filters/compression/parameters/hcsendcacheheaders FALSE |
IISReset