1 / 42

Applying Directives

Applying Directives. Directives are applied not in the order listed in the httpd.conf file, but in the following order: server configuration directives first (found in the httpd.conf file, or in files that are loaded via Include statements)

jasper
Download Presentation

Applying Directives

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Applying Directives • Directives are applied not in the order listed in the httpd.conf file, but in the following order: • server configuration directives first (found in the httpd.conf file, or in files that are loaded via Include statements) • they are applied in the order of httpd.conf and then Include files • virtual host configuration directives • a virtual host is this server acting as another server so that one server can handle requests targeting different servers (covered in ch 6) • these directives are also stored in either httpd.conf or Include files • directory containers • directories that are specified explicitly are applied first followed by directories that are specified using regular expressions • directives specified in .htaccess files • any directory can have an .htaccess file • file containers • location (URL) containers

  2. Context • Directives can be defined only in specific locations, these are known as contexts • The four contexts match the order from the last slide • server configuration – found in the httpd.conf file, Include files • a directive that has this context cannot appear inside of <VirtualHost> or <Directory> containers, nor in the .htaccess file • virtual host – found only in <VirtualHost> containers, typically located in the httpd.conf file (but possibly in Include files) • directory – any of <Directory>, <Location>, or <Files> container • .htaccess – any .htaccess file • Some directives can appear in multiple contexts, for instance TimeOut is definable in both server config and <VirtualHost> but not available in <Directory>, <Location>, <Files> or .htaccess • directory Option can be found in either <Directory> or .htaccess • NOTE: a directive defined in the wrong context will either yield an error message when apache is started, or will result in apache not starting at all

  3. <Directory> Directives • The <Directory> container allows you to specify the following directives • Options – we cover these in a few slides • AllowOverride – states which directives, if any, can override this definition using directives in later contexts • the default is All, that is, any directive can be overridden • <Directory /var/www/html> • AllowOverrideFollowSymLinks • </Directory> • here, only FollowSymLinks can be overridden in a later context such as in this case .htaccess file or <Files> or <Location> container • thus, in the above statement, no matter what is defined in the .htaccess file for that directory, only a FollowSymLinks directive could override what has already been defined here (or in a higher up directory <Directory> container)

  4. <Directory> Directives Continued • Allow and Deny statements are used to determine which users can access any content of this (or lower) directory • typically, you will provide specific IP addresses for access or denial, or the word All • you can also specify a port number in addition to or in place of the IP address • you precede your Allow/Deny statement(s) with an Order statement to indicate the order that Allow and Deny get applied (they are not applied in the order that they appear in the container) • Order allow,deny • Deny from all • there is no space in “allow,deny” or “deny,allow” • this states that first apply any allow statement and then any deny statement – in this case, since there is no allow, no one would be given access • Order allow,deny • Allow from All • Deny from 172.*.*.* • this allows access to everyone who is not in domain 172

  5. Additional Directives • There are dozens of directives available, here we spotlight a few of the more important ones • DefaultType • if apache cannot infer the type of a given file, this directive specifies a default as in DefaultType text/plain – if a given file has no extension and its type is unknown, assume it is text/plain • this directive can be used in httpd.conf, in a <Directory> or <VirtualHost> container, or in an .htaccess file • AcceptPathInfo • this directive determines whether a URL, which is partially valid but contains trailing information, should ignore the trailing information if a file is found • e.g., /text/here.html/more is the path and there is a file, here.html in /text, if AcceptPathInfo is set to On, then this URL is acceptable otherwise it generates 404 error

  6. Authentication Directives • Require • this directive selects which authenticated users can access a resource within this scope (e.g., this directory) and can be used in <Directory>, <Files> and .htaccess contexts • the Require statement is followed by one or more entities (separated by blanks) where entities are any of • user username • group groupname • valid-user (all valid users) • file-owner • file-group • we explore authentication in more detail in chapter 9 • Satisfy • in the case that Allow and Require are both used, is given to the user if they satisfy one of these restrictions but not both? • Satisfy is followed by either All or Any • all means both Allow and Require must be satisfied for access whereas Any means that (at least) one of them must be satisifed for access but not necessarily both (this is the difference between AND and OR)

  7. The Options Directive • Options – this directive allows you to list various features that you would like to take effect to this directory (and all subdirectories) • Indexes – if the URL does not include a file name and there is no file of the default name (e.g., index.html), then the contents of the directory will be displayed instead • without this option, a URL that does not include a file name for a directory that does not have a default file will result in a 404 error • FollowSymLinks – this option will allow Apache to follow a symbolic link set up in the Linux file system • without this, any symbolic links would be ignored and a file not found would result in a 404 error • NOTE: this directive is meaningless in Windows since Windows does not have symbolic links, so while you can use this directive in apache in Windows, it would not accomplish anything

  8. More Options • More options are listed below • ExecCGI – cgi scripts can be executed out of this directory • Includes – allows you to specify “server-side includes” • IncludesNOEXEC – like Includes except that you cannot execute scripts using #exec or #include • MultiViews – provides content negotiation • we will cover cgi scripts, includes and content negotiation in chapter 8 • SymLinksIfOwnerMatch – symbolic links can be followed as per FollowSymLinks but only if the link is owned by the owner of the target file/directory • All (all options are available*) and None (no options are available) • * - if you use All, it does not include MultiViews so that if you wanted everything and MultiViews, you would need to say Options All MultiViews (or list every option) • The Options are all specified on a single line as in • Options Includes FollowSymLinksExecCGI

  9. AllowOverride Directives • Aside from the Options just covered, we can add any of the following to an AllowOverride • AuthConfig • any of the authorization directives (which we cover in chapter 9) such as AuthName, AuthUserFiles, Require • FileInfo • any of the directives to control document types such as ErrorDocument, ForceType, LanguagePriority, DefaultType and SetHandler • Limit • allow the use of Order, Allow, Deny • Options • all of the previously listed options (e.g., FollowSymLinks, Indexes) but also directives like XBitHack, AddDescription, AddIcon, DefaultIcon, DirectoryIndex, FancyIndexing, HeaderName • we will cover many of these throughout the semester

  10. Inheriting and Overriding Options • Options are inherited from parent to child directories if you do not specify an Options directive for the child • for instance, if you have • <Directory /var/www/html> Options Indexes FollowSymLinks </Directory> • then the directory /var/www/html/foo would inherit Indexes and FollowSymLinks, but if you define • <Directory /var/www/html/foo> Options Includes </Directory> • then foo only has Includes as an Option (foo does not inherit either Indexes or FollowSymLinks) • To control what is inherited, use + and – • + before an option means “add” and – means “do not inherit” • <Directory /var/www/html/foo> Options +Includes –Indexes </Directory> • now, foo inherits FollowSymLinks and adds Includes but does not inherit Indexes

  11. <Files> • This container allows you to specify directives that impact only the listed file(s) • the directives impact all files in the file system of the given name, so this container is different from <Directory> which only impacts things in the stated directory(ies) • <Files> is a more specific context than <Directory> and .htaccess and so it can override any directives for <Directory> container and .htaccess of the directory storing these files • however, to override a directive, the AllowOverride statement must explicitly list the directive(s) to be overridden • although since AllowOverride All is the default, a missing AllowOverride statement means that the more specific context will override the outer context(s) • The <Files> container may appear in any of httpd.conf, <VirtualHost> containers, <Directory> containers and .htaccess files

  12. More on <Files> • As with <Directory>, the <Files> container allows regular expressions • the <Files> containers are processed in the order they are found and before any <Location> containers • If you would like to affect specific files but not all files of the specified name, you would want to restrict where the Files container takes effect • you would do this by placing the <Files> container inside another definition (<VirtualHost>, <Directory> container or .htaccess file) • this would allow the owner of a directory (e.g., ~foxr) to specify how a specific file or files should be treated/handled rather than how the entire directory should be treated • NOTE: all directives available for <Files> are also available for <Directory> (but not visa versa)

  13. Overriding <Files> Directives • Any file in the file system that matches the file in a <Files> • container will be impacted unless the <Files> container is nested • inside of another container (<Directory> or <VirtualHost>) or .htaccess • file in which case only the file(s) defined in that directory(ies) or • virtual host will be affected • <Files secret.html> • Order allow,deny • Deny from all • </Files> • <Directory /etc/apache2/htdocs/dir1> • <Files secret.html> • Order deny,allow • Allow from all • </Files> • </Directory> • All files in the web space called secret.html are inaccessible unless a file of • that name is found under the dir1 subdirectory

  14. .htaccess Files • For each directory in the path provided by the URL, apache checks to see if there is an .htaccess file • if so, the .htaccess file is loaded and all of its directives are enacted • the .htaccess file allows an owner of some subdirectory in the filespace to define his/her own directives • only certain directives can be placed in an .htaccess file, and since an .htaccess file specifies directives for an entire directory, you would not place any <Directory> containers there • the directives in the .htaccess file apply to the directory in which it is stored, but also any subdirectories (unless overridden by another .htaccess file lower in the file system) • the directives are applied in the order found going down the file system hierarchy • as with directives in <Directory> containers, inheritance of directives in .htaccess are controlled using + and -

  15. .htaccess Files and Performance • As a web administrator, you should not use .htaccess files just because you want to specify directives for a directory (these are best placed in the httpd.conf file as <Directory> containers) • the reason for the .htaccess is for users who do not have access to httpd.conf and want to set their own directives like FollowSymLinks or Indexes • .htaccess files tend to reduce performance of apache, not just because more time is required to process a request, but also because Apache must search for .htaccess files in higher directories • if we have a request for /etc/apache2/htdocs/users/cit436/labs and Apache finds an .htaccess file in this directory, then Apache must also search in /etc, /etc/apache2, /etc/apache2/htdocs, /etc/apache2/htdocs/users and /etc/apache2/htdocs/users/cit436 for additional .htaccess files

  16. More on .htaccess • You can alter the access file name by the AccessFileName directive as in • AccessFileName .acl • in this case, apache would look for .acl files in each directory instead of .htaccess • this directive would be placed in ether httpd.conf or a <VirtualHost> container (not in specific <Directory> containers) • this may be risky in that users may not be aware of the name of the access file, so if you do not use the default, make sure all users know the proper name! • As stated earlier, the directives in any .htaccess file must be able to be overridden which means that a <Directory> container for the given directory must include an AllowOverride statement • if you place your directives in <Directory> containers, then you don’t have to worry about using AllowOverride statements

  17. An Example In httpd.conf, we have the following <Directory> container <Directory /etc/apache2/htdocs> Options ExecCGI Indexes AllowOverride all </Directory> In the directory /etc/apache2/htdocs, we have an .htaccess file with the directive Options FollowSymLinks So in this directory, all 3 are available In the subdirectory /etc/apache2/htdocs/stuff, if we have an .htaccess file that contains the directive Options Includes then in stuff, we only have the directive Includes defined Instead, if we use Options +Includes then in stuff we have all 4 defined It is important to know what higher level directories also have .htaccess files

  18. <Location> • Location containers allow you to define directives to impact specific URLs • <Location> containers are evaluated in the order that they are found in the httpd.conf file after processing all <Directory>, .htaccess files and <Files> directives • the URL provided should only consist of the path, not the server name/port or file name • since this overlaps what a <Directory> container offers, there is little need for <Location> containers • although the rules change when being handled by a proxy server • we will explore this in more detail in chapter 11 • Directives available for <Directory> and .htaccess are also available for <Location> • as with <Directory> and <Files> containers, you can use regular expressions when defining the path and you can use <LocationMatch> if the entire path is specified using regex

  19. Handlers • A handler is the action to be taken by apache when asked to handle a particular type of file • Handlers can also be tied to specific locations as well • Many of the handlers are built-in but we might have to specify which handler to use in a number of cases • There are two handler directives • AddHandler name type • as in AddHandlercgi-script cgi • SetHandler name • this forces any file type as listed by an AddHandler for this handler’s name to be parsed through the handler as named • We will explore handlers in more detail as we need them • some of the built-in handlers allow apache to send a file with an already written http header (rather than generating one of its own), or to treat a file as a CGI script • handlers can also generate server information and status • we see this in chapter 7

  20. Modules • All of the directives so far discussed are part of the core apache server • they are automatically available when you compile and run apache • There are dozens of modules that are available as well which have their own directives available offering additional functionality such as • running cgiscrips • loading other languages (php, perl, etc) • user authentication via username/password pair • other security mechanisms • URL redirection and spell checking/correction • additional logging capabilities, additional status and information generating capabilities • cache and proxy capabilities • web development capabilities • database management and communications • file handlers and filters for mime types • negotiation

  21. Using Modules • To use directives from a module, you would have to first compile the module’s source code and add a LoadModule directive in your httpd.conf file • in Apache 2.2, many of the useful modules are part of Apache’s core so that you do not have to explicitly compile them or load them – you will explore some of these in lab 7 • there are some Apache modules that are not part of the core along with popular third party modules – you will explore some of these in lab 8 • non-core apache modules are part of the tarred file you already downloaded but third party modules require that you download them • One non-core Apache module is mpm_common for multiprocessing • there are a number of related modules to mpm_common • beos – optimized for the Be OS • mpm_netware – for Novell Netware • mpm_winnt – for Windows NT • prefork – non-threaded version • you can find a list of 3rd party modules at modules.apache.org

  22. As-Is Files • The module mod_asis.so allows you to return files “as is” • You would use this to embed HTTP header information in the file itself so that, rather than returning a header and the file, it just returns the file • the header information is already in the file • You need to load the asis module and enable as-is by doing AddHandler send-as-is asis • any file sent this way must • contain HTTP header information at the top of the file, followed by at least one blank line before the html and text • be saved as an .asis file (for instance foo.html.asis) • NOTE: since Apache will automatically add a response header that minimally contains HTTP/1.1 and the Date and Server information, do not include them in your own header

  23. Redirection • This is an external redirect in which apache responds that the requested URL is now found at another site • this message does not appear in the browser window but instead, the client’s browser sends out a new request for the returned URL • To perform redirection, you need to load the mod_alias module • now you supply ReDirect directives • ReDirectoriginalURLnewURL • As an example, your web site might contain news articles from other sites, rather than copying the article or placing an explicit link to that other site, you use redirection • if an article is known on your site as nku-news.php but is actually located at www.nku.edu/news/jan/story5.php then you can redirect as follows: • ReDirect /nku-news.php http://www.nku.edu/news/jan/story5.php • server returns a 30x status to inform your browser to redirect

  24. Four Types of Redirection • You can place a type of redirection in your directive immediately after the word ReDirect • The four forms are • temporary (use the word temp) – this is the default setting if the type is omitted • the web server returns a 302 status and the new URL • permanent – this returns the 301 status code and the new URL • see other (use seeother) – the resource has been replaced and the old content is no longer available, this returns the 303 status code and the new URL • gone – the resource has been permanently removed and the server returns 401 (but no URL) • ReDirectMatch is the same as ReDirect except that you use a regular expression to define the URL so that you can specify any number of possible files • for instance, all of the .gif files have been replaced with .jpg files • ReDirectMatch (.*)\.gif$ $1.jpg

  25. Aliases • Another feature of the mod_alias module is to define aliases for URLs • this is an internal redirect • The directive is Alias url path • where url is the expected URL path (e.g., /foo/bar/) and path is the internal replacement path where the path starts at the Linux root directory • As an example, imagine that people might reference materials stored in /pub but in fact the directory is stored in /etc/apache2/htdocs/pub/files, then you would use the directive • Alias /pub /var/pub/files • And now the URL //ipaddress/pub/bar/foo1.html becomes the address /etc/apache2/htdocs/pub/files/bar/foo1.html • the listing of both url and file must be consisent – if one ends with a / then the other must, and if one does not end with a / then the other must not • since the destination may be outside of DocumentRoot, you might need a <Directory> container to permit access (Allow from all)

  26. ReWriting • Aside from Alias as an internal redirect, you can also rewrite URLs using mod_rewrite • use this for internal or external rewrites • rewriting uses rules that you set up to perform a mapping • There are 9 directives available • RewriteBase – set base URL for per-directory rewrites • RewriteCond – a condition under which a rewrite will take place • you will have more than one of these • conditions will test variables defined in apache such as SERVER_PORT or HTTP_HOST • RewriteEngine – enables or disables rewriting (on or off) • RewriteLog and RewriteLogLevel – control logging of rewrites • RewriteMap – defines mapping function (not needed) • RewriteOptions – sets options like maximum number of rewrites • RewriteRule – the actual mapping or rule to translate the URL into something new • RewriteLock – sets the name of a lock file for mapping (not needed)

  27. Examples • Assume users web directories are stored in their home directories under public_html • users are often denoted as ~name • We want to intercept any URL that contains ~name in it and rewrite it to be /home/name/public_html • RewriteRule ^/~[A-Za-z0-9]+/?(.*) /home/$1/public_html/$2 • this rule takes anything that starts with ~name (where name can contain upper case, lower case and digits) and changes it to be /home/ followed by that name verbatim, and then adds /public_html prior to the remainder of the URL • this would change ~foxr/CIT436/Labs/lab1.doc to be /home/foxr/public_html/CIT436/Labs/lab1.doc • We want to ensure that there is a trailing / at the end of any URL • RewriteRule ^/[A-Za-z0-9]+/([^/])+)$ /$1/$2/ • this rule tacks a / onto any URL that does not contain one

  28. Conditional Directives • The <IfDefine> container tests to see if a value was supplied as a parameter when apache was started • this requires that you start apache from the command line, not from the GUI • the parameter follows –D, as in apachectl –Dspelling • the <IfDefine> container must include the expected parameter • as in <IfDefine Spelling> • the container will then include whatever directive(s) you want executed if the parameter was supplied • in this case, the container probably includes LoadModulespeling_module modules/mod_speling.so and CheckSpelling on • the container ends with </IfDefine> • <IfDefine> is an example of a conditional directive • the container’s directives are only enacted if the tested condition is true

  29. Two Other Conditional Directives • <IfModule> tests to see if a module has been loaded and if so, the directives in the container are enacted, otherwise the container is skipped • this can prevent errors by testing to see if a module has been compiled so that it can be loaded • <IfModulemodulename> or <IfModule !modulename> • modulename is the name of the file of the source code (will end in .c as in mod_speling.c) • for !modulename, we are testing to see if a module has not been compiled – we might want to use this in case we want to perform an action knowing that the module is not available • <IfVersion op value> tests to see which version of apache is being run • op is one of =, <, >, <=, >= or != • value can be an actual value like 2.1.0 or it can be a regular expression like 2.[1-2].[0-9] • this container is part of the mod_version module so you need to load mod_version to use it

  30. Spelling Errors • The mod_speling module (note that speling is misspelled on purpose) provides modest error correction capabilities for URLs that come close to actual file names • if apache cannot find the file as normal, the mod_speling module will examine the target directory for files or subdirectories whose names differ either by • case (upper versus lower case letters) • one miss-typed character • two transposed characters • having one extra character • having one fewer character • if apache finds a file that is a close match, this file is returned • if apache finds more than one file that is a close match, the entire list of matches is returned to the client so that the client can select the appropriate file • if apache finds no close matches, it returns a 404 error

  31. To Use this Module • First you need the proper LoadModule statement in your httpd.conf file • Next, place the directive CheckSpelling on • CheckSpelling can also take the argument off • but then you wouldn’t need the directive at all if you want to turn it off • This module will only correct names of files • not directories or user names (as in ~forx/) • not server names • there are modules for DNS that could potentially correct this • This sounds like a great module since people often will have typos, so why wouldn’t you want to use this? • this may slow the server down if spelling errors are common, if directories have a lot of files, and if there are a lot of files that are similarly spelt • consider a directory of 50 files, if the URL is misspelled, now the spell checker must compare all 50 files to the given URL to see if there is an off-by-one type error

  32. Examples • Imagine that you have a directory foo with files foo1.html, foo2.html and foo3.html • the URL entered is …/foo/foo.html • this does not match any of the 3 files but comes 1 character from matching all three • if CheckSpelling is on, you get the output shown below allowing you to select the correct URL • if CheckSpelling is off, you get a 404 error • the URL is …/foo/FOO1.html or …/foo/foo1.htm • the URL is changed to foo/foo1.html correctly • the URL is …/FOO/foo1.html • this yields a 404 error

  33. Customizing Response Headers • Apache generates a header for every request received • you are able to tailor these headers – you can add your own header to the default header, modify the header, or even delete the header • you might want to do this if you want to monitor your own apache server’s performance • This uses the mod_headers module • the directive is Header and has the following form • Header [condition] action headername [value] [env=[!]variable] • condition is optional and one of onsuccess or always • header actions are one of set, append, add, unset, echo • headername is optional but used to name the header generated • value is a list of one or more items that will appear in the header • env=variable or env=!variable is a test to see if an environment variable has been set or not • use this as a condition in place of the optional [condition] if desired

  34. Continued • The header action is one of • set – replace any header automatically generated with this new one • append – append this header to the automatically generated header • add – basically the same as append except that there may already be two or more headers • unset – remove the named header if there is one • echo – the named header(s) is echoed back in the response header • The value(s) consists of • %t – the time the request was received in Universal Coordinated Time (number of microseconds since Jan 1, 1970) • %D – the time from when the request was received to the time the headers are sent (duration) • %{FOOBAR} e – the contents of environment variable FOOBAR

  35. Examples • Header set MyHeader “%D %t” • replace the default header with this one that includes the duration and time of the request • the header might look like this: • MyHeader: D=3775428 t=991424704447256 • Header add MyHeader “Hi there” • this adds “Hi There” after the Apache generated header • SetEnvIfMyRequestmyvalue • HAVE_MyRequest • Header set MyHeader “%D %t mytext” env=HAVE_MyRequest • this will replace the header with one that reads • MyHeader: D=3775428 t=991424704447256 mytext • if MyRequest has the value myvalue

  36. Request Headers • You can also alter incoming headers to fit a different format as follows • RequestHeader action headername [value] [replacement] [early|env=[!]variable] • The action is one of set, append, add, merge, unset or edit • these are the same as the Response Header except merge which will append unless there is already a header of the given name in which case it replaces it, and edit which, if the header name is already present, will transform the header based on a regular expression mapping rule (similar to sed) • If the value contains spaces, the entire value must be enclosed in “” • as an example: RequestHeader edit Destination ^https: http: early • this header will cause https to be replaced with http (you might issue this during development of the website)

  37. Filters • Filters are used to transform files before being transmitted over the Internet • filters typically perform compression or decompression but not always • the mod_charset_lite module translates a file stored using the EBCDIC character set into a file stored using the ASCII character set • there are input filters and output filters • input filters: filter the body of a request • this would only be used if the http method is one that accompanies data like put, but otherwise is of little use • output filters: filter the data being returned • The mod_deflate module provides us with an output filter which we may want to use to compress large text files • mod_deflate uses the zlib open source library to perform compression

  38. mod_deflate Usage • The mod_deflate module adds the following directives: • DeflateBufferSize – set the size of the data to be compressed at one time, defaults to 8KB • a larger value will result in greater compression but will take more CPU time to perform the compression • DeflateCompressionLevel – how much compression to be applied, between 1 (less compression) and 9 • less compression means a larger file but takes less CPU time • DeflateWindowSize – 1 to 15, defaults to 15 • larger means greater compression • DeflateFilterNote – for logging (discussed in three slides) • DeflateMemLevel – specifies how much memory the zlib program can use during compression (from 1 – 9) – • this is only useful if you need to limit zlib’s memory usage • Because the module is configured so that the best performance is set by default, you can omit all of these directives unless you want logging on

  39. To Use Deflate • You must specify the file(s) that should be compressed • use a <Directory> or <Files> container • You will place your directives in the container (including any or all of the five previous directives) along with two more directives • the AddOutputFilterByType directive to specify the mime type(s) that should be compressed • the SetOutputFilter directive to specify the filter (in this case, the filter will be DEFLATE) • As an example, imagine that you want to compress large text files • assume you have created a public directory to store all of the large text files in bigdocs, then you might use this container • <Directory /etc/apache2/htdocs/pub/bigdocs> • AddOutputFilterByType text/html text/plain text/xml • SetOutputFilter DEFLATE • </Directory>

  40. <Location />SetOutputFilter DEFLATE# Netscape 4.x has some problems...BrowserMatch ^Mozilla/4 gzip-only-text/html# Netscape 4.06-4.08 have some more problemsBrowserMatch ^Mozilla/4\.0[678] no-gzip# MSIE masquerades as Netscape, but it is fineBrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html# Don't compress imagesSetEnvIfNoCase Request_URI \\.(?:gif|jpe?g|png)$ no-gzip dont-vary# Make sure proxies don't deliver the wrong contentHeader append Vary User-Agent env=!dont-vary</Location> Example Compress anything other than images but also making sure that the browser can handle this form of compression

  41. Logging Using Deflate • To determine just how useful your deflate settings are, you will want to inspect the log information using the DeflateFilterNote directive • DeflateFilterNote type name • this directive has a context of either server or virtual host, so you do not place this in the container that specifies Deflate • Type is the type of information to store, one of • input – byte count of the filter’s input stream • output – byte count of the filter’s output stream • ratio – the value (output / input * 100), this is the default type • to specify multiple types, you use multiple DeflateFilterNote directives • name is optional and can be used in a format statement (see below) • if you want more than one type, use multiple Deflate directives • Follow this directive with LogFormat and CustomLog which specify the format of the log and which log file to write to • DeflateFilterNote Ratio r • LogFormat ‘“%r” %b{r}n) “%{User-agent}i”’ deflate

  42. Other Modules of Note • mod_dir – for redirection • you are supposed to add a trailing slash if the redirection URL ends with a directory (not a file) but you might forget this • so the mod_dir offers DirectorySlash (On or Off) directive to ensure that this will not result in a 3xx or 4xx error status code • this module also contains DirectoryIndex (from chapter 4) • mod_userdir – to allow users to have their own web directories stored under their /home directories • the directive UserDir allows you to specify the name of the web directory given to each user, defaults to public_html • we will cover this in more detail in chapter 6 • Other modules will be examined throughout the semester

More Related