Tuning mod_include

SSI commands are handled by the mod_include module, which comes with the standard Apache distribution. [6] The mod_include filter is controlled by special SGML directives that allow conditional includes of files or programs. You can set, check, and print environment variables to sniff browsers or perform time-based tasks . (You can skip the next section if you don't have access to Apache configuration files.)

[6] Apache Software Foundation, "Apache Module mod_include" [online], (Forest Hill, MD: Apache Software Foundation, 2002 [cited 13 November 2002]), available from the Internet at http://httpd.apache.org/docs-2.0/mod/mod_include.html.

Here are some ways you can speed up mod_include:

  • Consider XBitHack or .shtml .

  • Run mod_include per virtual server.

  • Use AllowOverride None to avoid .htaccess queries.

  • Enable caching with XBitHack Full or mod_expires.

Consider XBitHack or .shtml

To tell Apache which files to parse for SSI commands, you can use .shtml and .html suffixes:

 # To use server-parsed HTML files  AddType text/html .html AddType text/html .shtml AddHandler server-parsed shtml AddHandler server-parsed html 

However, telling Apache to parse all .html files for SSI is inefficient. Using .shtml or XBitHack to parse only files with the execute bit set to On is more efficient, as you see here:

 <VirtualHost            xxx.xx.xx.xx>      DocumentRoot        /www/webref/webref     ServerName          www.webreference.com     ErrorDocument       404 /_404.html     DirectoryIndex      index.html index.shtml index.wml     XBitHack On </VirtualHost> 

Run mod_include per Virtual Server

To enable includes, you use the Options Includes directive. You can either place this directive in the root directory section, which enables includes for the entire server, or you can place it within a Virtual Host section with a Directory entry for speed:

 <Directory /www/webref/webref>      Options FollowSymlinks Includes     Options IncludesNOEXEC     order deny,allow     deny from all </Directory> 

Note that we use the IncludesNOEXEC version, which closes a possible security hole.

Use AllowOverride None

The AllowOverride directive controls how the .htaccess files work, one per directory. By using the httpd.conf file, we can ignore .htaccess files and speed up the server. Without this directive, Apache traverses the directory tree above the requested resource, looking for .htaccess directives that apply, slowing down each request:

 <Directory />      AllowOverride None     Options FollowSymLinks     order deny,allow     deny from all </Directory> 

Enable Caching with XBitHack Full or mod_expires

By default, Apache does not send the last modified date for SSI pages, which can prevent your pages from being cached. There are two solutions, XBitHack Full , and mod_expires. XBitHack Full sends the last modified date of the original file, ignoring any included files. mod_expires allows you to set expiration times for your files, allowing them to be cached. For more details, see the Apache documentation. [7]

[7] Apache Software Foundation, "Introduction to Server-Side Includes" [online].

Now that you've got your server tuned to run SSI, let's look at some more advanced ways to use SSI. Besides creating SSI templates and nested includes, you can perform browser sniffing with SSI to include conditional code.

 



Speed Up Your Site[c] Web Site Optimization
Speed Up Your Site[c] Web Site Optimization
ISBN: 596515081
EAN: N/A
Year: 2005
Pages: 135

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net