Social Media

Category Archives for Uncategorized

Simple Apache Performance Improvements

This post to collect together a number of simple performance improvements using apache. It demonstrates using mod_expires, mod_deflate, mod_cache and mod_headers.

.htaccess or httpd.conf

httpd.conf provides the core apache configuration, while .htaccess provides a directory specific configuration. The preference is to use httpd.conf where possible, because using htaccess results in a search for htaccess on every sub-directory of a request, for each request. Depending on your hosting this decision may be out of your hands.

mod_deflate

mod_deflate tells apache to compress responses from your application server. The options are –

  • AddOutputFilterByType – To use this option you must enable mod_filter –
    LoadModule filter_module modules/mod_filter.so
  • AddOutputFilterByType DEFLATE text/html text/xml text/css text/plain
  • Extension –
If you use AddOutputFilterByType then you need to make sure you have the mime-types defined

Other directives –

DeflateCompressionLevel – 1 to 9 – the higher the value, the greater compression but the cost is higher CPU

You can also enable mod_deflate logging to see the compression ratios on your files.

Putting it together –

mod_expires

This module sets the Expires HTTP header and max-age of Cache-Control in HTTP header.

The format is –

A typical configuration would be –

mod_headers

This plugin customises HTTP request and response headers, and we can use it to set the max-age on Cache-Control –

ETag

An ETag is a unique ID for a resource and is configured per server. The problem is that in some clustered environments you can end up caching the same resource due to them having different ETags. A decision on disabling ETag’s should be made on an environment basis, as disabling them forces the browser to rely on Cache-Control and Expires headers.

The syntax to disable is –

References

1 4 5 6 7 8 45