My WordPress host adopts the lamp architecture, namely, Linux + Apache + MySQL + PHP. I suddenly thought that a gzip compression can speed up webpage access. So I want to perform a test, you can also learn how to enable gzip compression. The following figure shows how to enable gzip compression in Apache:
1. Add the following rules to the httpd. conf or. htaccess file in the blog root directory (the Apache server must support mod_deflate)
<Ifmodule mod_deflate.c>
Addoutputfilter deflate HTML XML PHP JS CSS
</Ifmodule>
Or add
<Ifmodule mod_deflate.c>
Addoutputfilterbytype deflate text/HTML text/XML application/X-httpd-PHP application/X-JavaScript text/CSS
</Ifmodule>
After checking, Apache on the host supports mod_deflate (use httpd-m to check whether the mod_deflate module exists, or view your httpd. does loadmodules In the conf file have this mod_deflate module enabled?) copy and paste the above Code to httpd. at the end of the conf file, restart the apache service to implement gzip compression.
If Apache on the host does not support mod_deflate, PHP on the host supports zlib, that is, Gzip compression. For details, see the following description:
For static webpages (HTML, JS, CSS), set URL rewrite first:
<Ifmodule mod_rewrite.c>
Rewriteengine on
Rewritebase/blog # change to the directory of your blog
Rewritecond % {request_filename}-F
Rewriterule ^ (. *) (JS | CSS | HTML | htm) $/gzip. php? File = $1 $2 & type = $2 [l]
</Ifmodule>
You can request the gzip. php file through URL rewrite (the file needs to be placed in the "/" Directory), so that the gzip compression of the static file is OK.
Also, for webpages dynamically output by PHP, the common page is the WP output page, which can be implemented through a plug-in (gzippy) and directly go to the WP background, enter "gzippy" in the plug-in search and install it.
Gzippy has only one sentence:
<? PHP
Function gzippy (){
Ob_start ('ob _ gzhandler ');
}
If (! Stristr ($ _ server ['request _ URI '], 'tinymce ')&&! Ini_get ('zlib. output_compression ')){
Add_action ('init ', 'gzippy ');
}
?>
At the same time, Apache on the host does not support mod_deflate. If you want installed Apache to support this module, You can compile only the files mod_deflate.c and mod_headers.c required by the deflate module.
These two files are located in the {APACHE-Src}/modules/filters/directory (where {APACHE-Src} is the directory where the Apache source file is located ).
Use the following command to compile the two source files separately.
[Rootmin @ localhost ~] # {APACHE-bin}/apxs-I-a-c {APACHE-Src}/modules/filters/mod_deflate.c
[Rootmin @ localhost ~] # {APACHE-bin}/apxs-I-a-c {APACHE-Src}/modules/filters/mod_headers.c
When install the header module the src directory is {APACHE-Src}/modules/metadata/mod_headers.c
So we need change the command as follows: {APACHE-bin}/apxs-I-a-c {APACHE-Src}/modules/metadata/mod_headers.c
{APACHE-bin} is the bin directory under the Apache installation directory. Configure the module directly in httpd. conf.
Many times you may encounter a compilation error when compiling the deflate module separately. The prompt is:
Cannot load/opt/Apache/modules/mod_deflate.so into server:/opt/Apache/modules/mod_deflate.so: Undefined Symbol: deflate
Solution: Edit/usr/local/apache2/bin/APR-config
Modify the value of ldflags in the file to "-LZ", and then re-compile the mod_deflate module. apxs-ica mod_deflate.c.
To save unnecessary trouble, add the-enable-Deflate-enable-headers parameter when compiling and installing Apache.
My website is complete. Now let's take a look at the effect:
Source: http://paulfzm.iteye.com/blog/1175093