Performance tuning for web servers

Slashdot it! Delicious Share on Facebook Tweet! Digg!

Avoiding Unnecessary Administrative I/O

Frequently, admins use .htaccess files that control the Apache server directly from the DocumentRoot and also take care of things like IP limits, password requests, and rewrites. Here, the directive AllowOverride is put to use. The disadvantage, however, is that the web server will need to check for each request whether an .htaccess file that needs processing exists in the respective directory. Therefore, if at all possible, you should universally set the AllowOverride directive to None and then explicitly allow it only for those directories where it is used.

You can always configure an .htaccess file straight from the Apache configuration. Often, however, there is no direct access to the configuration files in a shared hosting environment even if the web applications require this capability.

The SymLinksIfOwnerMatch option from the Options directive behaves in a similar fashion. For reasons of security, it is actually better when the directive is missing from a shared hosting environment. From a performance perspective, the absence of this directive is not so good because the server then has to monitor the owner of symlinks when the server is accessed.

If you want to wring out the last bit of performance from a web server, you should probably use the DirectoryIndex directive without a wildcard, (index ). Likewise, it's a good idea to deactivate the MultiViews option and use type maps instead. Finally, the send file support should be set to EnableSendfile On even though this may at times cause problems with network mounts.

Browser Caching

The mod_expires module can tell the browser to cache static data for long periods of time. This reduces the number of requests to the Apache web server. The module is activated on Debian and Ubuntu via

a2enmod expires

The next step is to specify the file types that should be cached (Listing 5). Additionally, it is important to deliver content in a compressed format. The mod_deflate module assumes this task. A standard configuration for this module already exists on Debian (see Listing 6).

Listing 5

Expiration Date for File Types

ExpiresActive on
ExpiresByType image/gif "access plus 1 months"
ExpiresByType image/jpeg "access plus 1 months"
ExpiresByType image/png "access plus 1 months
ExpiresByType application/x-font-woff "access plus 1 months"
ExpiresByType application/javascript "access plus 1 months"
ExpiresByType text/css "access plus 1 months"

Listing 6

Standard Configuration for mod_deflate

AddOutputFilterByType DEFLATE text/html text/plain text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/x-javascript \
  application/javascript application/ecmascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/xml

Starting with Apache 2.4, the mod_deflate module only compresses files when the resulting overhead is smaller than the overhead for compressed data. Under certain circumstances, the overhead doesn't touch very small files. Listing 7 shows how you can check expiration dates and compression with the aid of the server header.

Listing 7

Server Header Check

root@debian:~# wget --server-response \
  --header="accept-encoding: gzip" http://localhost/test.css
--2015-06-07 06:06:57--  http://localhost/test.css
Resolving localhost (localhost)... ::1,
Connecting to localhost (localhost)|::1|:80... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 200 OK
  Date: Sun, 07 Jun 2015 04:06:57 GMT
  Server: Apache/2.4.10 (Debian)
  Last-Modified: Fri, 05 Jun 2015 13:02:45 GMT
  ETag: "aa0-517c4e8861a8a-gzip"
  Accept-Ranges: bytes
  Vary: Accept-Encoding
  Content-Encoding: gzip
  Cache-Control: max-age=2592000
  Expires: Tue, 07 Jul 2015 04:06:57 GMT
  Content-Length: 102
  Keep-Alive: timeout=5, max=100
  Connection: Keep-Alive
  Content-Type: text/css
Length: 102 [text/css]
Saving to: 'test.css'

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $0.99
(incl. VAT)

Buy Ubuntu User

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Perfect setup and installation of ownCloud 9

    ownCloud makes it possible to operate a private cloud on an intranet of almost any size. All you need is a standard LAMP environment, which comes with almost every Linux server.

  • Pydio is a free cloud solution

    Most cloud solutions for small networks are based on ownCloud or, less frequently, Seafile. Pydio is the third open source product trying to gain a foothold as a cloud solution.

  • Installing and testing Nextcloud

    Leading ownCloud developers, including the project founder Frank Karlitschek, became dissatisfied with the direction of the project, so they started Nextcloud, a fork of the code and a new company. The goal is to create a better balance among the company, clients, and users. We take a look at how Nextcloud is faring.

  • Puppet Labs Announces Puppet Enterprise


    Puppet Labs, provider of open source systems management solutions, announced the release of Puppet Enterprise, the first commercially supported version of Puppet.

  • Optimizing, securing, and tuning your network

    In an age of perpetually interconnected devices, keeping your network and its services safe and running smoothly is a high priority whether you're an admin or an end-user.