Configuring Apache to speed up your website

  

How to speed up your website, it should be a concern for webmasters and bloggers. The speed at which a site is opened is related to many aspects, such as server performance, network speed, and web design of the site.

In the article "Best Practices for Speeding Up Your Web Site" on the Yahoo! Developer Network, we've introduced 34 suggestions for speeding up your site. Three of them are related to the optimization of the Web server. This article is specifically for these three suggestions to set up Apache to achieve the purpose of website acceleration.


Setting the expiration time for files
The purpose of this is to control the browser to cache files we don't modify often, such as images, css, js, etc., so that when the viewer opens another web page At the time of the reduction of the download of the file, the purpose of speeding up the website. To enable Apache to increase the file validity period, the browser cache can be implemented in two ways:

The first one: use the mod_headers module to increase the validity period of the file

Load the mod_headers module and add it to the configuration file. :

LoadModule headers_module modules/mod_headers.so
Configure the mod_headers module, set the jpg jpeg gif png ico js css swf flv and other files Expires: (Expires head can only be a fixed time, the image is said It seems that the expiration time of the product. The purpose of this is to be compatible with browsers that do not support Cache-Control. If Cache-Control is set and the browser supports Cache-Control, the Cache-Control setting is preferred. Support Cache-Control file header)

<FilesMatch "\\.(jpg| Jpeg| Gif| Png| Ico| Js| Css| Swf| Flv)$">
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
</FilesMatch>
Configure the mod_headers module, set jpg jpeg gif png ico js css swf flv Cache-Control of the file: (The Cache-Control control is more flexible. It sets a valid time, which is like the shelf life of the product. The following 604800 units are seconds, which is the effective time for setting the file to 1 week) Br>

<FilesMatch "\\.(jpg| Jpeg| Gif| Png| Ico| Swf| Flv| Js| Css)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
Second: Use the mod_expires module to add Expires

to the file. The mod_expires module, added in the configuration file:

LoadModule expires_module modules/mod_expires.so
Configure the mod_expires module:

ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 weeks"
ExpiresByType text/css access plus 3 days
ExpiresByType image/gif "access plus 1 month "
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType text/plain "access plus 1 weeks"
ExpiresByType application/x-shockwave- Flash "access plus 1 month"
ExpiresByType video/x-flv "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/html "access plus 1 weeks"
Enable Gzip compression
To enable Apache to implement Gzip compression Open the mod_deflate module and the mod_headers module. The mod_headers module has been enabled. You can open the mod_deflate module here. Open the Apache configuration file and add:

LoadModule deflate_module modules/mod_deflate.so
Configure the mod_deflate module. Let it compress html xml css php js and other files:


<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-httpd- Php application/x-javascript
AddOutputFilter DEFLATE html xml css php js
</ifmodule>
turn off ETags
Even if Expires or Cache-Control is set, sometimes browsers will often access resources when accessing resources Because the ETag exists and re-download the entire resource, it is easy to close them:

FileETag None
I believe that after setting the above 3 items, your site browsing speed will increase a lot if you can't feel it. For speed improvements, install Firefox's YSlow plugin to check if your settings are successful.

Copyright © Windows knowledge All Rights Reserved