Difference between revisions of "Apache 2 - Performances"
Line 1: | Line 1: | ||
+ | [[Category:Linux]] | ||
+ | |||
These are performances tricks for Apache2. | These are performances tricks for Apache2. | ||
Latest revision as of 17:05, 10 June 2014
These are performances tricks for Apache2.
Contents
Mod deflate: improved the bandwidth
To improve the bandwidth, you can compress pages and type of content. To do so, you need a specific module for Apache: mod_deflate
=> You can improved your bandwidth from 20 to 30%.
Mod_deflate
Enable Apache2 module:
a2enmod deflate
Create dedicated files:
touch /var/log/apache2/deflate.log
chown www-data:www-data /var/log/apache2/deflate.log
chmod 740 /var/log/apache2/deflate.log
Configuration
Edit your web server configuration file:
vim /etc/apache2/mods-available/deflate.conf
Add the following lines:
### Bandwidth optimization
<IfModule mod_deflate.c>
<IfModule mod_filter.c>
# these are known to be safe with MSIE 6
AddOutputFilterByType DEFLATE text/html text/plain text/xml
# everything else may cause problems with MSIE 6
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/xml
# Logs
DeflateFilterNote deflate_ratio
LogFormat "%v %h %l %u %t \"%r\" %>s %b"
CustomLog /var/log/apache2/deflate.log vhost_with_deflate_info
</IfModule>
</IfModule>
Restart your web server:
service apache2 restart
Mod expires: use the cache of your clients
Another way to improve performances and bandwidth: use the client's cache. To do so, you need a specific module for Apache: mod_expires
Mod_expires
a2enmod expires
Configuration
Edit your web server configuration file:
vim /etc/apache2/mods-available/expires.conf
Add the following lines
#### Client's cache settings
<IfModule mod_expires.c>
ExpiresActive on
# set the default to 24 hours
ExpiresDefault "access plus 24 hours"
# cache shockwave-flash for 2 weeks (days | weeks | mounths | years)
ExpiresByType application/x-shockwave-flash "access plus 2 weeks"
ExpiresByType flv-application/octet-stream "access plus 3 days"
# cache common graphics for 3 days
ExpiresByType image/jpg "access plus 2 weeks"
ExpiresByType image/gif "access plus 2 weeks"
ExpiresByType image/jpeg "access plus 2 weeks"
ExpiresByType image/png "access plus 2 weeks"
# cache CSS for 24 hours
ExpiresByType text/css "access plus 24 hours"
</IfModule>
Reload the module (this will add a symlink to the new configuration file)
a2enmod expires
Restart your web server:
service apache2 restart