How to open GZip for your Discuz!
本帖最后由 leon 于 2013-9-28 19:48 编辑I just finished config, and I find it worth to share.
Because it improve your discuz!x's visit speed obviously.
Test result
Whether compressYes
Typegzip
Original33277 bytes
After8631 bytes
Percent74.06%
My VPS is a centos 6.4 server, so I will show you about the procedure in a simple way.
1. Check your /etc/httpd/conf/httpd.conf, make sure they are available.LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so 2. Add the code to your httpd.conf, if you use a visual host, add to .htcaccess.<IfModule mod_deflate.c>
#Necessary, tell your apache to compress
SetOutputFilter DEFLATE
#compress rate 1~9, suggest 6
DeflateCompressionLevel 6
#set to not compress gif,jpg,jpeg,png, because no much use and cost your CPU too much
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
#like above , but set to exe, tgz, gz..etc
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
#Set to work with text/htmltext/csstext/plain, etc
AddOutputFilterByType DEFLATE text
#It will work on javascript files
AddOutputFilterByType DEFLATE application/ms* application/vnd* application/postscript application/javascript application/x-javascript
#It will work on php files
AddOutputFilterByType DEFLATE application/x-httpd-php application/x-httpd-fastphp
#Netscape 4.x has some problem with this function, so only conpress text/html
BrowserMatch ^Mozilla/4 gzip-only-text/html
#Netscape 4.06-4.08 has more problem, not open for them
BrowserMatch ^Mozilla/4.0 no-gzip
# A hack for IE, seems like for resolve some problem, I don't know the details
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>3. Modify configuration in Discuz. Open"/config/config_global.php"
Replace:
$_config['output']['gzip'] ='0';
To:
$_config['output']['gzip']= '1';
4. restart your apache.
#service httpd restrat
5. Test your site here. It is a chinese site, you can translate it by google.
http://tool.chinaz.com/Gzips/
Tips: How to verify whether your apache server support Gzip?
1. Input by cmd line: #httpd -M
2. Check these 2 module.
deflate_module (shared)
headers_module (shared)
Another Way is to Simply add These Lines to .htaaccess and save...
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
i tried your method i addded the code to htaccess and enabled gzip in config but got internal server error 500 Ask your hosting support to check if mod_deflate is enabled.
Pages:
[1]