Difference between revisions of "Apache 2 - Performances"

(Created page with "These are performances tricks for Apache2. =Mod deflate: improved the bandwidth= To improve the bandwidth, you can compress pages and type of content. => You can improv...")
 
Line 6: Line 6:
 
=Mod deflate: improved the bandwidth=
 
=Mod deflate: improved the bandwidth=
  
To improve the bandwidth, you can compress pages and type of content.  
+
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%.
 
=> You can improved your bandwidth from 20 to 30%.
Line 13: Line 13:
 
==Mod_deflate==
 
==Mod_deflate==
  
To do so, you need a specific module for Apache: mod_deflate
+
Enable Apache2 module:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
a2enmod deflate
 
a2enmod deflate
 +
</syntaxhighlight>
 +
 +
 +
Create dedicated files:
 +
 +
<syntaxhighlight lang="bash">
 
touch /var/log/apache2/deflate.log
 
touch /var/log/apache2/deflate.log
 
chown www-data:www-data /var/log/apache2/deflate.log
 
chown www-data:www-data /var/log/apache2/deflate.log
Line 28: Line 34:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
vim /etc/apache2/conf.d/deflate.conf
+
vim /etc/apache2/mods-available/deflate.conf
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
  
 
Add the following lines:
 
Add the following lines:
 +
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 +
 
### Bandwidth optimization
 
### Bandwidth optimization
 
<IfModule mod_deflate.c>
 
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/x-javascript
+
        <IfModule mod_filter.c>
DeflateFilterNote deflate_ratio
+
                # these are known to be safe with MSIE 6
LogFormat "%v %h %l %u %t \"%r\" %>s %b"
+
                AddOutputFilterByType DEFLATE text/html text/plain text/xml
CustomLog /var/log/apache2/deflate.log vhost_with_deflate_info
+
 
 +
                # 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>
 
</IfModule>
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
  
 
Restart your web server:
 
Restart your web server:
 +
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
/etc/init.d/apache2 restart
+
service apache2 restart
 
</syntaxhighlight>
 
</syntaxhighlight>
  
  
==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: 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==
 +
 
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
a2enmod expires
 
a2enmod expires
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
 +
==Configuration==
  
 
Edit your web server configuration file:
 
Edit your web server configuration file:
 +
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
vim /etc/apache2/expires.conf
+
vim /etc/apache2/mods-available/expires.conf
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
  
 
Add the following lines
 
Add the following lines
 +
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
#### Client's cache settings
 
#### Client's cache settings
Line 80: Line 112:
 
</IfModule>
 
</IfModule>
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
 +
Reload the module (this will add a symlink to the new configuration file)
 +
 +
<syntaxhighlight lang="bash">
 +
a2enmod expires
 +
</syntaxhighlight>
 +
  
 
Restart your web server:
 
Restart your web server:
 +
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
/etc/init.d/apache2 restart
+
service apache2 restart
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 17:32, 8 June 2014

These are performances tricks for Apache2.



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