]> granicus.if.org Git - apache/blob - docs/manual/env.xml.ja
update transformation
[apache] / docs / manual / env.xml.ja
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE manualpage SYSTEM "./style/manualpage.dtd">
3 <?xml-stylesheet type="text/xsl" href="./style/manual.ja.xsl"?>
4 <!-- English Revision: 659902:782860 (outdated) -->
5
6 <!--
7  Licensed to the Apache Software Foundation (ASF) under one or more
8  contributor license agreements.  See the NOTICE file distributed with
9  this work for additional information regarding copyright ownership.
10  The ASF licenses this file to You under the Apache License, Version 2.0
11  (the "License"); you may not use this file except in compliance with
12  the License.  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
22
23 <manualpage metafile="env.xml.meta">
24
25   <title>Apache の環境変数</title>
26
27   <summary>
28     <p>Apache HTTP サーバは<em>環境変数</em>と呼ばれる、名前のついた
29     変数に情報を記憶する仕組みを提供しています。この情報はログ収集や
30     アクセス制御などのいろいろな操作を制御するために使うことができます。
31     これらの変数は CGI スクリプトなどの外部プログラムと通信するためにも
32     使われます。この文書はそれらの変数の操作方法と使用方法をいくつか
33     紹介します。</p>
34
35     <p>これらの変数は<em>環境変数</em>と呼ばれていますが、オペレーティング
36     システムによって制御されている環境変数と同じではありません。
37     実際は、これらの変数は Apache の内部構造の中に記憶され、操作されています。
38     それらは、CGI や SSI スクリプトに渡されたときだけ、実際の
39     オペレーティングシステムの環境変数になります。サーバ自身が
40     実行されているオペレーティングシステムの環境を操作したい場合は、
41     オペレーティングシステムのシェルが提供している標準の環境変数の
42     操作方法を使わなければなりません。</p>
43   </summary>
44
45   <section id="setting">
46     <title>環境変数の設定</title>
47     <related>
48       <modulelist>
49         <module>mod_env</module>
50         <module>mod_rewrite</module>
51         <module>mod_setenvif</module>
52         <module>mod_unique_id</module>
53       </modulelist>
54       <directivelist>
55         <directive module="mod_setenvif">BrowserMatch</directive>
56         <directive module="mod_setenvif">BrowserMatchNoCase</directive>
57         <directive module="mod_env">PassEnv</directive>
58         <directive module="mod_rewrite">RewriteRule</directive>
59         <directive module="mod_env">SetEnv</directive>
60         <directive module="mod_setenvif">SetEnvIf</directive>
61         <directive module="mod_setenvif">SetEnvIfNoCase</directive>
62         <directive module="mod_env">UnsetEnv</directive>
63       </directivelist>
64     </related>
65
66     <section id="basic-manipulation">
67         <title>基本的な環境の操作</title>
68
69         <p>Apache において環境変数を設定する一番基本的な方法は、
70         無条件に環境変数を設定する <directive module="mod_env"
71         >SetEnv</directive> ディレクティブを使用することです。
72         <directive module="mod_env">PassEnv</directive> 
73         ディレクティブにより、Apache が起動されたシェルの
74         環境変数を渡すこともできます。</p>
75
76     </section>
77     <section id="conditional">
78         <title>リクエスト毎に条件に基づいて設定する</title>
79
80         <p>より柔軟性を高めるために、mod_setenvif
81         で提供されているディレクティブを使用することで、リクエストの
82         特性に基づいて環境変数を設定することができます。例えば、特定のブラウザ
83         (User-Agent) のリクエストや特定の Referer [意図的な綴りです]
84         <transnote>正しい綴りは referrer ですが、HTTP の仕様では Referer
85         となっています</transnote>ヘッダが見つかったときのみ変数を設定することができます。
86         mod_rewrite の <directive module="mod_rewrite">RewriteRule</directive>
87         ディレクティブにおいて環境変数を設定する <code>[E=...]</code>
88         オプションを使用することで、
89         より柔軟な設定を行なうことができます。</p>
90
91     </section>
92     <section id="unique-identifiers">
93         <title>一意な識別子</title>
94
95         <p>mod_unique_id は、非常に限られた条件の下で
96         「すべて」のリクエストについて、一意であることが保証されている値を環境変数
97         <code>UNIQUE_ID</code> に設定します。</p>
98
99     </section>
100     <section id="standard-cgi">
101         <title>標準 CGI 変数</title>
102
103         <p>Apache の設定ファイルで設定された環境変数とシェルから渡される
104         環境変数に加えて、CGI スクリプトと SSI ページには <a
105         href="http://cgi-spec.golux.com">CGI の仕様</a>で要求されている、
106         リクエストのメタ情報を持った環境変数の組が提供されます。</p>
107
108     </section>
109     <section id="caveats">
110         <title>いくつかの注意</title>
111
112         <ul>
113           <li>環境を操作するディレクティブを使って標準 CGI
114           変数を上書きしたり変更したりすることはできません。</li>
115
116           <li>CGI スクリプトを起動するために <program>suexec</program>
117           が使用されている場合、CGI スクリプトが起動するために、環境変数は<em
118           >安全</em>な環境変数の組に整理されます。
119           この安全な環境変数の集合は、コンパイル時に <code>suexec.c</code>
120           で定義されます。</li>
121
122           <li>移植性のために、環境変数の名前はアルファベット、
123           数字とアンダースコア <transnote>'_'</transnote> だけから成ります。
124           さらに、最初の文字は数字であってはいけません。
125           この制限に合わない文字は CGI スクリプトと SSI
126           ページに渡されるときにアンダースコアに置換されます。</li>
127           
128           <li><directive module="mod_env">SetEnv</directive> はリクエスト処理の
129           段階の中でも遅くに実行されます。つまり
130           <directive module="mod_setenvif">SetEnvIf</directive> や
131           <directive module="mod_rewrite">RewriteCond</directive>
132           などからは、変数がそこで設定されていることがわかりません。</li>
133         </ul>
134     </section>
135   </section>
136   <section id="using">
137     <title>環境変数の使用</title>
138
139     <related>
140       <modulelist>
141         <module>mod_authz_host</module>
142         <module>mod_cgi</module>
143         <module>mod_ext_filter</module>
144         <module>mod_headers</module>
145         <module>mod_include</module>
146         <module>mod_log_config</module>
147         <module>mod_rewrite</module>
148       </modulelist>
149       <directivelist>
150         <directive module="mod_authz_host">Allow</directive>
151         <directive module="mod_log_config">CustomLog</directive>
152         <directive module="mod_authz_host">Deny</directive>
153         <directive module="mod_ext_filter">ExtFilterDefine</directive>
154         <directive module="mod_headers">Header</directive>
155         <directive module="mod_log_config">LogFormat</directive>
156         <directive module="mod_rewrite">RewriteCond</directive>
157         <directive module="mod_rewrite">RewriteRule</directive>
158       </directivelist>
159     </related>
160
161     <section id="cgi-scripts">
162         <title>CGI スクリプト</title>
163
164         <p>環境変数の主な利用法の一つは、CGI スクリプトに情報を伝えることです。
165         上で説明されているように、CGI スクリプトに渡される環境変数は Apache
166         の設定により設定される変数に加えて、リクエストの標準のメタ情報を含んでいます。
167         詳細は <a href="howto/cgi.html">CGI チュートリアル</a>
168         を参照してください。</p>
169
170     </section>
171     <section id="ssi-pages">
172         <title>SSI ページ</title>
173
174         <p>mod_include の <code>INCLUDES</code> フィルタで処理される
175         server-parsed (SSI) ドキュメントでは、<code>echo</code>
176         要素を使用すると環境変数が出力されます。
177         また、ページのある部分がリクエストの性質に応じて変更されるように、
178         環境変数をフロー制御要素で使うことができます。詳細は
179         <a href="howto/ssi.html">SSI チュートリアル</a> を参照してください。</p>
180
181     </section>
182     <section id="access-control">
183         <title>アクセス制御</title>
184
185         <p><code>allow from env=</code> ディレクティブと <code>deny from env=</code>
186         ディレクティブを使用して、サーバへのアクセスを環境変数の値で制御することができます。
187         <directive module="mod_setenvif">SetEnvIf</directive>
188         ディレクティブと組み合わせることで、クライアントの特性に基づいて
189         サーバへのアクセス制御を柔軟に行なうことができるようになります。
190         たとえば、これらのディレクティブを使用して、特定のブラウザ (User-Agent)
191         からのアクセスを拒否することができます。</p>
192
193     </section>
194     <section id="logging">
195         <title>条件付きログ記録</title>
196
197         <p><directive module="mod_log_config">LogFormat</directive>
198         ディレクティブのオプション <code>%e</code>
199         を使用することで、環境変数をアクセスログに記録することができます。さらに、
200         <directive module="mod_log_config">CustomLog</directive>
201         ディレクティブの条件分岐式を使用することで、
202         環境変数の値によってリクエストをログに記録するかどうかを決めることができます。
203         <directive module="mod_setenvif">SetEnvIf</directive>
204         ディレクティブと組み合わせることで、
205         どのリクエストをログに記録するかを柔軟に制御することが可能になります。たとえば、
206         <code>gif</code> で終わるファイル名へのリクエストはログに記録しない、
207         違うサブネットのクライアントからのリクエストだけをログに記録する、
208         という選択が可能です。</p>
209
210     </section>
211     <section id="response-headers">
212         <title>条件付き応答ヘッダ</title>
213
214         <p><directive module="mod_headers">Header</directive>
215         ディレクティブは環境変数の存在や不在によってクライアントへの応答に特定の
216         HTTP ヘッダを付けるかどうかを決めることができます。
217         これにより、たとえば、クライアントからのリクエスト
218         にあるヘッダがある場合にのみ特定の応答ヘッダを送る、というようなことが
219         できます。</p>
220
221     </section>
222
223     <section id="external-filter">
224         <title>外部フィルタの適用</title>
225
226         <p><directive module="mod_ext_filter">ExtFilterDefine</directive>
227         ディレクティブを使用して
228         <module>mod_ext_filter</module> で設定される外部フィルタは、
229         <code>disableenv=</code> と <code>enableenv=</code>
230         オプションを使って、環境変数による条件付き適用ができます。</p>
231     </section>
232
233     <section id="url-rewriting">
234         <title>URL の書き換え</title>
235
236         <p><directive module="mod_rewrite">RewriteCond</directive>
237         ディレクティブで<em>評価文字列</em>として
238         <code>%{ENV:...}</code> 式を指定することで、mod_rewrite
239         の書き換えエンジンが環境変数に基いて条件分岐を行なうことができます。
240         mod_rewrite が使用可能な変数で <code>ENV:</code> が前についていない変数は、
241         実際は環境変数ではないということに注意してください。
242         それらは他のモジュールからは使用できない mod_rewrite 用の特別な変数です。
243         </p>
244     </section>
245   </section>
246
247   <section id="special">
248     <title>特別な目的の環境変数</title>
249
250         <p>互換性の問題を解決するために、特定のクライアントと通信しているときは
251         Apache の動作を変更できる機構が導入されました。できるだけ柔軟にするために、
252         これらの機構は環境変数を定義することで呼び出されます。普通は、
253         <directive module="mod_setenvif">BrowserMatch</directive>
254         ディレクティブを使いますが、たとえば <directive module="mod_env"
255         >SetEnv</directive> ディレクティブや <directive module="mod_env"
256         >PassEnv</directive> ディレクティブも使用することができます。</p>
257
258     <section id="downgrade">
259         <title>downgrade-1.0</title>
260
261         <p>これを指定することで、リクエストが HTTP/1.0
262         より新しいプロトコルの場合でも、HTTP/1.0 として扱われます。</p>
263
264     </section>
265     <section id="force-gzip">
266         <title>force-gzip</title>
267           <p><code>DEFLATE</code> フィルタが使用するように設定されているときに、
268           この環境変数はブラウザの accept-encoding の設定を無視して常に
269           圧縮された出力を送るようにします。</p>
270     </section>
271     <section id="force-no-vary">
272         <title>force-no-vary</title>
273
274         <p>応答ヘッダがクライアントに送られる前に <code>Vary</code>
275         フィールドを取り除きます。
276         クライアントの中にはこのフィールドを正しく解釈しないものがあります。
277         この変数を設定することでその問題を回避することができます。
278         この変数を設定すると、<strong>force-response-1.0</strong>
279         が設定されたことになります。</p>
280
281     </section>
282     <section id="force-response">
283         <title>force-response-1.0</title>
284
285         <p>これが設定されていると、HTTP/1.0 リクエストを発行するクライアントに対しては
286         常に HTTP/1.0 で応答するようになります。この機能は、
287         元々は AOL のプロキシの問題のために実装されました。HTTP/1.0 クライアントの中には、
288         HTTP/1.1 の応答を返されると正しく動作しないものがあるかもしれません。
289         この機能を使用することで、そのようなクライアントとの間の互換性問題を解決できます。</p>
290     </section>
291
292     <section id="gzip-only-text-html">
293         <title>gzip-only-text/html</title>
294
295         <p>これが 1 に設定されると、この変数は <code>text/html</code>
296         以外のコンテントタイプに対する、<module>mod_deflate</module>
297         提供の <code>DEFLATE</code> 出力フィルタを無効にします。
298         また、静的に、既に圧縮されたファイルを使用したい場合、
299         (gzip だけでなく、"identity" と異なる全てのエンコードに対して)
300         <module>mod_negotiation</module> も変数を評価します。</p>
301     </section>
302
303     <section id="no-gzip"><title>no-gzip</title>
304         <p>セットされると、<module>mod_deflate</module> の
305         <code>DEFLATE</code> フィルタがオフになります。
306         そして <module>mod_negotiation</module>
307         はエンコードされたリソースを送らないようにします。</p>
308     </section>
309
310     <section id="nokeepalive">
311         <title>nokeepalive</title>
312
313         <p>これが設定されている場合は、<directive module="core"
314         >KeepAlive</directive> を使用しないようにします。</p>
315
316     <section id="prefer-language"><title>prefer-language</title>
317
318         <p><module>mod_negotiation</module> の挙動に影響を与えます。
319         (<code>en</code>, <code>ja</code>, <code>x-klingon</code>といった)
320         言語タグが格納されていれば、その言語の variant を送信しようとします。
321         そのような variant がない場合は、
322         通常の<a href="content-negotiation.html">ネゴシエーション</a>処理が
323         適用されます。</p>
324
325     </section>
326
327     </section>
328     <section id="redirect-carefully">
329         <title>redirect-carefully</title>
330
331         <p>これはクライアントへのリダイレクトの送信をサーバがより注意深く
332         行なうようにします。
333         これは通常、リダイレクトに際してクライアントに
334         問題があることが分かっている場合に使われます。この機能は元々は
335         マイクロソフトのウェブフォルダのソフトが DAV
336         メソッドによるディレクトリのリソースへのリダイレクトの扱いに
337         問題がり、それを回避するために実装されました。</p>
338
339     </section>
340
341    <section id="suppress-error-charset">
342        <title>suppress-error-charset</title>
343
344     <p><em>Apache 2.2 以降で利用可能</em></p>
345
346     <p>クライアントのリクエストに対する応答としてリダイレクトを送信する際、
347     レスポンスにはリダイレクトが自動的に行なえない (行なわれない)
348     場合に表示するテキストが含まれます。
349     通常、このテキストに合致したキャラクタセット、ISO-8859-1
350     でラベル付けをします。</p>
351     <p>しかし、リダイレクト先が別の文字セットを使っている場合、
352     ある問題のあるブラウザのバージョンでは、
353     リダイレクト先の実際の文字セットの代わりに、
354     リダイレクト元の文字セットを使ってしまうことがあります。
355     その結果、例えば変な描画が行なわれたりして、読めなくなったりします。</p>
356     <p>この環境変数を設定することで、リダイレクションテキストに対する
357     キャラクタセットの指定を除去しますので、それら問題のあるブラウザでも
358     リダイレクト先の文字セットを正しく使うようにできます。</p>
359
360     <note type="warning">
361       <title>セキュリティ</title> 
362
363       <p>文字セットを指定せずにエラーページを送信すると、
364       クロスサイトスクリプティング <transnote>XSS</transnote>
365       攻撃の危険性がでてきます。
366       HTTP/1.1 仕様に準拠していなくて、コンテンツの中身から文字セットを
367       "推測" しようとするブラウザ (MSIE) が実際にあるからです。
368       そのようなブラウザは UTF-7 文字セットを使って簡単に騙すことができます。
369       クロスサイトスクリプティング攻撃を防ぐために実装されている
370       通常のエスケープ機構が、入力データ中にある UTF-7 で
371       エンコードされたコンテンツ (リクエスト URI など) には
372       うまく動作しないからです。</p>
373     </note>
374
375    </section>
376
377    <section id="proxy"><title>force-proxy-request-1.0, proxy-nokeepalive, proxy-sendchunked, proxy-sendcl</title>
378
379    <p>これらの指示子は <module>mod_proxy</module> の挙動を変更します。
380    詳細は <module>mod_proxy</module> のドキュメントをご参照ください。</p>
381    </section>
382
383   </section>
384
385   <section id="examples">
386     <title>例</title>
387
388     <section id="misbehaving">
389         <title>おかしな挙動をするクライアントに対してプロトコルの動作を変更する</title>
390
391         <p>クライアントに関する既知の問題に対処するために、以下の行を
392         httpd.conf に入れることを推奨しています。</p>
393         <p>古いバージョンの Apache では、クライアントの問題に対応するために
394         httpd.conf に次の行を加えるよう推奨されていましたが、
395         今となっては、問題としていたクライアントは実際には見かけることは
396         なくなってきたので、この設定はもはや必要ないかもしれません。</p>
397 <example><pre>
398 #
399 # The following directives modify normal HTTP response behavior.
400 # The first directive disables keepalive for Netscape 2.x and browsers that
401 # spoof it. There are known problems with these browser implementations.
402 # The second directive is for Microsoft Internet Explorer 4.0b2
403 # which has a broken HTTP/1.1 implementation and does not properly
404 # support keepalive when it is used on 301 or 302 (redirect) responses.
405 #
406 BrowserMatch "Mozilla/2" nokeepalive
407 BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
408
409 #
410 # The following directive disables HTTP/1.1 responses to browsers which
411 # are in violation of the HTTP/1.0 spec by not being able to grok a
412 # basic 1.1 response.
413 #
414 BrowserMatch "RealPlayer 4\.0" force-response-1.0
415 BrowserMatch "Java/1\.0" force-response-1.0
416 BrowserMatch "JDK/1\.0" force-response-1.0</pre></example>
417
418     </section>
419     <section id="no-img-log">
420         <title>画像へのリクエストをアクセスログに記録しない</title>
421
422         <p>この例では、画像へのリクエストがアクセスログに現れないようにします。
423         これを変更することで、特定のディレクトリのログ収集をやめたり、
424         特定のホストからのリクエストのログ収集をやめたりすることが簡単にできます。
425         </p>
426     <example><pre>
427 SetEnvIf Request_URI \.gif image-request
428 SetEnvIf Request_URI \.jpg image-request
429 SetEnvIf Request_URI \.png image-request
430 CustomLog logs/access_log common env=!image-request</pre></example>
431
432     </section>
433     <section id="image-theft">
434         <title>「画像の盗用」を防ぐ</title>
435
436         <p>この例は、別のサーバにいる人が、あなたのサーバにある画像を
437         inline 画像として使用することを防ぎます。
438         これは推奨されている設定ではありませんが、ある限定された状況では有効です。
439         ここでは、すべての画像は <code>/web/images</code>
440         というディレクトリにあると仮定します。</p>
441     <example><pre>
442 SetEnvIf Referer "^http://www\.example\.com/" local_referal
443 # Allow browsers that do not send Referer info
444 SetEnvIf Referer "^$" local_referal
445 &lt;Directory /web/images&gt;
446    Order Deny,Allow
447    Deny from all
448    Allow from env=local_referal
449 &lt;/Directory&gt;</pre></example>
450
451         <p>この手法に関する詳しい情報は ServerWatch にあるチュートリアル
452         「<a href="http://www.serverwatch.com/tutorials/article.php/1132731"
453         >Keeping Your Images from Adorning Other Sites</a>
454         」を参照してください。</p>
455     </section>
456   </section>
457 </manualpage>