home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 May / Gamestar_62_2004-05_dvd.iso / Programy / apache_2.0.48-win32-x86-no_ssl.msi / Data.Cab / F252204_env.xml < prev    next >
Extensible Markup Language  |  2003-06-22  |  18KB  |  412 lines

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE manualpage SYSTEM "./style/manualpage.dtd">
  3. <?xml-stylesheet type="text/xsl" href="./style/manual.en.xsl"?>
  4.  
  5. <manualpage metafile="env.xml.meta">
  6.  
  7.   <title>Environment Variables in Apache</title>
  8.  
  9.   <summary>
  10.     <p>The Apache HTTP Server provides a mechanism for storing
  11.     information in named variables that are called <em>environment
  12.     variables</em>. This information can be used to control various
  13.     operations such as logging or access control. The variables are
  14.     also used as a mechanism to communicate with external programs
  15.     such as CGI scripts. This document discusses different ways to
  16.     manipulate and use these variables.</p>
  17.  
  18.     <p>Although these variables are referred to as <em>environment
  19.     variables</em>, they are not the same as the environment
  20.     variables controlled by the underlying operating system.
  21.     Instead, these variables are stored and manipulated in an
  22.     internal Apache structure. They only become actual operating
  23.     system environment variables when they are provided to CGI
  24.     scripts and Server Side Include scripts. If you wish to
  25.     manipulate the operating system environment under which the
  26.     server itself runs, you must use the standard environment
  27.     manipulation mechanisms provided by your operating system
  28.     shell.</p>
  29.   </summary>
  30.  
  31.   <section id="setting">
  32.     <title>Setting Environment Variables</title>
  33.     <related>
  34.       <modulelist>
  35.         <module>mod_env</module>
  36.         <module>mod_rewrite</module>
  37.         <module>mod_setenvif</module>
  38.         <module>mod_unique_id</module>
  39.       </modulelist>
  40.       <directivelist>
  41.         <directive module="mod_setenvif">BrowserMatch</directive>
  42.         <directive module="mod_setenvif">BrowserMatchNoCase</directive>
  43.         <directive module="mod_env">PassEnv</directive>
  44.         <directive module="mod_rewrite">RewriteRule</directive>
  45.         <directive module="mod_env">SetEnv</directive>
  46.         <directive module="mod_setenvif">SetEnvIf</directive>
  47.         <directive module="mod_setenvif">SetEnvIfNoCase</directive>
  48.         <directive module="mod_env">UnsetEnv</directive>
  49.       </directivelist>
  50.     </related>
  51.  
  52.     <section id="basic-manipulation">
  53.         <title>Basic Environment Manipulation</title>
  54.  
  55.         <p>The most basic way to set an environment variable in Apache
  56.         is using the unconditional <directive module="mod_env"
  57.         >SetEnv</directive> directive. Variables may also be passed from
  58.         the environment of the shell which started the server using the
  59.         <directive module="mod_env">PassEnv</directive> directive.</p>
  60.  
  61.     </section>
  62.     <section id="conditional">
  63.         <title>Conditional Per-Request Settings</title>
  64.  
  65.         <p>For additional flexibility, the directives provided by
  66.         mod_setenvif allow environment variables to be set on a
  67.         per-request basis, conditional on characteristics of particular
  68.         requests. For example, a variable could be set only when a
  69.         specific browser (User-Agent) is making a request, or only when
  70.         a specific Referer [sic] header is found. Even more flexibility
  71.         is available through the mod_rewrite's <directive 
  72.         module="mod_rewrite">RewriteRule</directive> which uses the 
  73.         <code>[E=...]</code> option to set environment variables.</p>
  74.  
  75.     </section>
  76.     <section id="unique-identifiers">
  77.         <title>Unique Identifiers</title>
  78.  
  79.         <p>Finally, mod_unique_id sets the environment variable
  80.         <code>UNIQUE_ID</code> for each request to a value which is
  81.         guaranteed to be unique across "all" requests under very
  82.         specific conditions.</p>
  83.  
  84.     </section>
  85.     <section id="standard-cgi">
  86.         <title>Standard CGI Variables</title>
  87.  
  88.         <p>In addition to all environment variables set within the
  89.         Apache configuration and passed from the shell, CGI scripts and
  90.         SSI pages are provided with a set of environment variables
  91.         containing meta-information about the request as required by
  92.         the <a href="http://cgi-spec.golux.com/">CGI
  93.         specification</a>.</p>
  94.  
  95.     </section>
  96.     <section id="caveats">
  97.         <title>Some Caveats</title>
  98.  
  99.         <ul>
  100.           <li>It is not possible to override or change the standard CGI
  101.           variables using the environment manipulation directives.</li>
  102.  
  103.           <li>When <a href="suexec.html">suexec</a> is used to launch
  104.           CGI scripts, the environment will be cleaned down to a set of
  105.           <em>safe</em> variables before CGI scripts are launched. The
  106.           list of <em>safe</em> variables is defined at compile-time in
  107.           <code>suexec.c</code>.</li>
  108.  
  109.           <li>For portability reasons, the names of environment
  110.           variables may contain only letters, numbers, and the
  111.           underscore character. In addition, the first character may
  112.           not be a number. Characters which do not match this
  113.           restriction will be replaced by an underscore when passed to
  114.           CGI scripts and SSI pages.</li>
  115.         </ul>
  116.     </section>
  117.   </section>
  118.   <section id="using">
  119.     <title>Using Environment Variables</title>
  120.  
  121.     <related>
  122.       <modulelist>
  123.         <module>mod_access</module>
  124.         <module>mod_cgi</module>
  125.         <module>mod_ext_filter</module>
  126.         <module>mod_headers</module>
  127.         <module>mod_include</module>
  128.         <module>mod_log_config</module>
  129.         <module>mod_rewrite</module>
  130.       </modulelist>
  131.       <directivelist>
  132.         <directive module="mod_access">Allow</directive>
  133.         <directive module="mod_log_config">CustomLog</directive>
  134.         <directive module="mod_access">Deny</directive>
  135.         <directive module="mod_ext_filter">ExtFilterDefine</directive>
  136.         <directive module="mod_headers">Header</directive>
  137.         <directive module="mod_log_config">LogFormat</directive>
  138.         <directive module="mod_rewrite">RewriteCond</directive>
  139.         <directive module="mod_rewrite">RewriteRule</directive>
  140.       </directivelist>
  141.     </related>
  142.  
  143.     <section id="cgi-scripts">
  144.         <title>CGI Scripts</title>
  145.  
  146.         <p>One of the primary uses of environment variables is to
  147.         communicate information to CGI scripts. As discussed above, the
  148.         environment passed to CGI scripts includes standard
  149.         meta-information about the request in addition to any variables
  150.         set within the Apache configuration. For more details, see the
  151.         <a href="howto/cgi.html">CGI tutorial</a>.</p>
  152.  
  153.     </section>
  154.     <section id="ssi-pages">
  155.         <title>SSI Pages</title>
  156.  
  157.         <p>Server-parsed (SSI) documents processed by mod_include's
  158.         <code>INCLUDES</code> filter can print environment variables
  159.         using the <code>echo</code> element, and can use environment
  160.         variables in flow control elements to makes parts of a page
  161.         conditional on characteristics of a request. Apache also
  162.         provides SSI pages with the standard CGI environment variables
  163.         as discussed above. For more details, see the <a
  164.         href="howto/ssi.html">SSI tutorial</a>.</p>
  165.  
  166.     </section>
  167.     <section id="access-control">
  168.         <title>Access Control</title>
  169.  
  170.         <p>Access to the server can be controlled based on the value of
  171.         environment variables using the <code>allow from env=</code>
  172.         and <code>deny from env=</code> directives. In combination with
  173.         <directive module="mod_setenvif">SetEnvIf</directive>, this 
  174.         allows for flexible control of access to the server based on 
  175.         characteristics of the client. For example, you can use these 
  176.         directives to deny access to a particular browser (User-Agent).
  177.         </p>
  178.  
  179.     </section>
  180.     <section id="logging">
  181.         <title>Conditional Logging</title>
  182.  
  183.         <p>Environment variables can be logged in the access log using
  184.         the <directive module="mod_log_config">LogFormat</directive>
  185.         option <code>%e</code>. In addition, the decision on whether
  186.         or not to log requests can be made based on the status of 
  187.         environment variables using the conditional form of the 
  188.         <directive module="mod_log_config">CustomLog</directive>
  189.         directive. In combination with <directive module="mod_setenvif"
  190.         >SetEnvIf</directive> this allows for flexible control of which 
  191.         requests are logged. For example, you can choose not to log 
  192.         requests for filenames ending in <code>gif</code>, or you can
  193.         choose to only log requests from clients which are outside your
  194.         subnet.</p>
  195.  
  196.     </section>
  197.     <section id="response-headers">
  198.         <title>Conditional Response Headers</title>
  199.  
  200.         <p>The <directive module="mod_headers">Header</directive>
  201.         directive can use the presence or
  202.         absence of an environment variable to determine whether or not
  203.         a certain HTTP header will be placed in the response to the
  204.         client. This allows, for example, a certain response header to
  205.         be sent only if a corresponding header is received in the
  206.         request from the client.</p>
  207.  
  208.     </section>
  209.  
  210.     <section id="external-filter">
  211.         <title>External Filter Activation</title>
  212.  
  213.         <p>External filters configured by <module>mod_ext_filter</module>
  214.         using the <directive
  215.         module="mod_ext_filter">ExtFilterDefine</directive> directive can
  216.         by activated conditional on an environment variable using the
  217.         <code>disableenv=</code> and <code>enableenv=</code> options.</p>
  218.     </section>
  219.  
  220.     <section id="url-rewriting">
  221.         <title>URL Rewriting</title>
  222.  
  223.         <p>The <code>%{ENV:...}</code> form of <em>TestString</em> in
  224.         the <directive module="mod_rewrite">RewriteCond</directive>
  225.         allows mod_rewrite's rewrite
  226.         engine to make decisions conditional on environment variables.
  227.         Note that the variables accessible in mod_rewrite without the
  228.         <code>ENV:</code> prefix are not actually environment
  229.         variables. Rather, they are variables special to mod_rewrite
  230.         which cannot be accessed from other modules.</p>
  231.     </section>
  232.   </section>
  233.  
  234.   <section id="special">
  235.     <title>Special Purpose Environment Variables</title>
  236.  
  237.         <p>Interoperability problems have led to the introduction of
  238.         mechanisms to modify the way Apache behaves when talking to
  239.         particular clients. To make these mechanisms as flexible as
  240.         possible, they are invoked by defining environment variables,
  241.         typically with <directive module="mod_setenvif">BrowserMatch</directive>,
  242.         though <directive module="mod_env">SetEnv</directive> and 
  243.         <directive module="mod_env">PassEnv</directive> could also be used,
  244.         for example.</p>
  245.  
  246.     <section id="downgrade">
  247.         <title>downgrade-1.0</title>
  248.  
  249.         <p>This forces the request to be treated as a HTTP/1.0 request
  250.         even if it was in a later dialect.</p>
  251.  
  252.     </section>
  253.     <section id="force-no-vary">
  254.         <title>force-no-vary</title>
  255.  
  256.         <p>This causes any <code>Vary</code> fields to be removed from
  257.         the response header before it is sent back to the client. Some
  258.         clients don't interpret this field correctly (see the <a
  259.         href="misc/known_client_problems.html">known client
  260.         problems</a> page); setting this variable can work around this
  261.         problem. Setting this variable also implies
  262.         <strong>force-response-1.0</strong>.</p>
  263.  
  264.     </section>
  265.     <section id="force-response">
  266.         <title>force-response-1.0</title>
  267.  
  268.       <p>This forces an HTTP/1.0 response to clients making an HTTP/1.0
  269.       request. It was originally
  270.       implemented as a result of a problem with AOL's proxies. Some
  271.       HTTP/1.0 clients may not behave correctly when given an HTTP/1.1
  272.       response, and this can be used to interoperate with them.</p>
  273.  
  274.     </section>
  275.  
  276.     <section id="gzip-only-text-html">
  277.         <title>gzip-only-text/html</title>
  278.  
  279.         <p>When set to a value of "1", this variable disables the DEFLATE
  280.         output filter provided by <module>mod_deflate</module> for
  281.         content-types other than <code>text/html</code>.</p>
  282.     </section>
  283.  
  284.     <section id="no-gzip"><title>no-gzip</title>
  285.  
  286.         <p>When set, the <code>DEFLATE</code> filter of
  287.         <module>mod_deflate</module> will be turned off.</p>
  288.  
  289.     </section>
  290.  
  291.     <section id="nokeepalive">
  292.         <title>nokeepalive</title>
  293.  
  294.         <p>This disables <directive module="core">KeepAlive</directive> when set.</p>
  295.  
  296.     </section>
  297.  
  298.     <section id="prefer-language"><title>prefer-language</title>
  299.  
  300.         <p>This influences <module>mod_negotiation</module>'s behaviour. If
  301.         it contains a language tag (such as <code>en</code>, <code>ja</code>
  302.         or <code>x-klingon</code>), <module>mod_negotiation</module> tries
  303.         to deliver a variant with that language. If there's no such variant,
  304.         the normal <a href="content-negotiation.html">negotiation</a> process
  305.         applies.</p>
  306.  
  307.     </section>
  308.  
  309.     <section id="redirect-carefully">
  310.         <title>redirect-carefully</title>
  311.  
  312.         <p>This forces the server to be more careful when sending a redirect
  313.         to the client.  This is typically used when a client has a known
  314.         problem handling redirects.  This was originally implemented as a
  315.         result of a problem with Microsoft's WebFolders software which has
  316.         a problem handling redirects on directory resources via DAV 
  317.         methods.</p>
  318.  
  319.     </section>
  320.  
  321.    <section id="suppress-error-charset">
  322.        <title>suppress-error-charset</title>
  323.  
  324.     <p><em>Available in versions after 2.0.40</em></p>
  325.  
  326.     <p>When Apache issues a redirect in response to a client request,
  327.     the response includes some actual text to be displayed in case
  328.     the client can't (or doesn't) automatically follow the redirection.
  329.     Apache ordinarily labels this text according to the character set
  330.     which it uses, which is ISO-8859-1.</p>
  331.     <p> However, if the redirection is to a page that uses a different
  332.     character set, some broken browser versions will try to use the
  333.     character set from the redirection text rather than the actual page.
  334.     This can result in Greek, for instance, being incorrectly rendered.</p>
  335.     <p>Setting this environment variable causes Apache to omit the character
  336.     set for the redirection text, and these broken browsers will then correctly
  337.     use that of the destination page.</p>
  338.  
  339.    </section>
  340.  
  341.   </section>
  342.  
  343.   <section id="examples">
  344.     <title>Examples</title>
  345.  
  346.     <section id="misbehaving">
  347.         <title>Changing protocol behavior with misbehaving clients</title>
  348.  
  349.         <p>We recommend that the following lines be included in
  350.         httpd.conf to deal with known client problems.</p>
  351. <example><pre>
  352. #
  353. # The following directives modify normal HTTP response behavior.
  354. # The first directive disables keepalive for Netscape 2.x and browsers that
  355. # spoof it. There are known problems with these browser implementations.
  356. # The second directive is for Microsoft Internet Explorer 4.0b2
  357. # which has a broken HTTP/1.1 implementation and does not properly
  358. # support keepalive when it is used on 301 or 302 (redirect) responses.
  359. #
  360. BrowserMatch "Mozilla/2" nokeepalive
  361. BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
  362.  
  363. #
  364. # The following directive disables HTTP/1.1 responses to browsers which
  365. # are in violation of the HTTP/1.0 spec by not being able to grok a
  366. # basic 1.1 response.
  367. #
  368. BrowserMatch "RealPlayer 4\.0" force-response-1.0
  369. BrowserMatch "Java/1\.0" force-response-1.0
  370. BrowserMatch "JDK/1\.0" force-response-1.0</pre></example>
  371.  
  372.     </section>
  373.     <section id="no-img-log">
  374.         <title>Do not log requests for images in the access log</title>
  375.  
  376.         <p>This example keeps requests for images from appearing in the
  377.         access log. It can be easily modified to prevent logging of
  378.         particular directories, or to prevent logging of requests
  379.         coming from particular hosts.</p>
  380.     <example><pre>
  381. SetEnvIf Request_URI \.gif image-request
  382. SetEnvIf Request_URI \.jpg image-request
  383. SetEnvIf Request_URI \.png image-request
  384. CustomLog logs/access_log common env=!image-request</pre></example>
  385.  
  386.     </section>
  387.     <section id="image-theft">
  388.         <title>Prevent "Image Theft"</title>
  389.  
  390.         <p>This example shows how to keep people not on your server
  391.         from using images on your server as inline-images on their
  392.         pages. This is not a recommended configuration, but it can work
  393.         in limited circumstances. We assume that all your images are in
  394.         a directory called /web/images.</p>
  395.     <example><pre>
  396. SetEnvIf Referer "^http://www.example.com/" local_referal
  397. # Allow browsers that do not send Referer info
  398. SetEnvIf Referer "^$" local_referal
  399. <Directory /web/images>
  400.    Order Deny,Allow
  401.    Deny from all
  402.    Allow from env=local_referal
  403. </Directory></pre></example>
  404.  
  405.         <p>For more information about this technique, see the
  406.         ApacheToday tutorial " <a
  407.         href="http://apachetoday.com/news_story.php3?ltsn=2000-06-14-002-01-PS">
  408.     Keeping Your Images from Adorning Other Sites</a>".</p>
  409.     </section>
  410.   </section>
  411. </manualpage>
  412.