Time: 2020-12-08 www.sdyserver.cn
How to enable GZIP compression on the server

How to enable GZIP function in APACHE

 


Apache needs to start GZIP to see if the mod_deflate module has been opened, if not, it needs to be loaded first, in the configuration file httpd.conf


LoadModule deflate_module modules/mod_deflate.so


LoadModule headers_module modules/mod_headers.so


Remove the # in front. DNSLA recommends that customers who do not understand Apache configuration files should back up the configuration files before modifying the configuration files.


After opening the module, add the following content to the bottom blank of the httpd.conf configuration file:



<ifmodule mod_deflate.c>


SetOutputFilter DEFLATE


SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary


SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary


SetEnvIfNoCase Request_URI .(?:pdf|mov|avi|mp3|mp4|rm)$ no-gzip dont-vary


DeflateCompressionLevel 6


AddOutputFilterByType DEFLATE text/html text/plain text/xml Application/x-httpd-php


AddOutputFilter DEFLATE js css


</ifmodule>


Among them, DeflateCompressionLevel means the compression level, which is divided into 1-9. Level 9 is the highest. It is not recommended to use a compression ratio that is too high, which will cause too much burden on the CPU.






How to enable GZIP function in IIS

 


Open the IIS management tool, right-click the website to open the website properties, and enable HTTP compression in the Service tab. It is not recommended to select compressed application files, but you must select compressed static files, otherwise it will be equal to no compression and load balance will not be achieved. . Then select the server extension under my site, create a new server extension, named GZIP, and add the file path below: c:\windows\system32\inetsrv\gzip.dll, and then enable this extension. DNSLA reminds everyone that it is not over yet. The third step is to modify the configuration file. Before the configuration file, stop the IIS service. (DNSLA reminds everyone to close the IIS service first). Open C:\Windows\System32\inetsrv\MetaBase .xml, this file is very large, find the following piece of information:


<IIsCompressionScheme Location ="/LM/W3SVC/Filters/Compression/gzip"


HcCompressionDll="%windir%\system32\inetsrv\gzip.dll"


HcCreateFlags="1"


HcDoDynamicCompression="TRUE"


HcDoOnDemandCompression="TRUE"


HcDoStaticCompression="TRUE"


HcDynamicCompressionLevel="0"


HcFileExtensions="htm


html


txt"


HcOnDemandCompLevel="10"


HcPriority="1"


HcScriptFileExtensions="asp


dll


exe"


>


</IIsCompressionScheme>


Modifying this file is to add some file suffixes to be compressed, where HcFileExtensions is the extension of static files, adding js and css, etc.; HcScriptFileExtensions is the extension of dynamic files, adding aspx, HcDynamicCompressionLevel is changed to 9, (0-10, 6 is the most cost-effective one).


Then you need to restart the IIS service.





How to enable GZIP function in Nginx


Compared with apache and IIS nginx, it is much easier to start GZIP. You only need to open the configuration file nginx.conf to find gzip on and remove the preceding comment symbol # to start the GZIP service. Then configure GZIP.


The following is a relatively optimized configuration, DNSLA recommends using it.


Gzip on;


gzip_min_length 1024;


gzip_buffers 4 8k;


gzip_types text/plain application/x-JAVAscript text/css application/xml;