Performance tuning for web servers
|
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, 127.0.0.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
Pages: 6
(incl. VAT)