]> granicus.if.org Git - apache/blob - docs/manual/sections.xml.ja
XML update.
[apache] / docs / manual / sections.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: 420990:1636195 (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="sections.xml.meta">
24
25 <title>セクションの設定</title>
26
27 <summary> <p><a href="configuring.html">設定ファイル</a>中のディレクティブは
28 サーバ全体に適用されたり、特定のディレクトリやファイル、ホスト、URL にのみ
29 適用されるように制限したりすることができます。この文書は設定用のセクションの
30 コンテナや <code>.htaccess</code> ファイルを使って他の設定ディレクティブの
31 スコープを変更する方法を説明します。</p>
32 </summary>
33
34 <section id="types"><title>設定用セクションコンテナの種類</title>
35
36 <related>
37 <modulelist>
38 <module>core</module>
39 <module>mod_version</module>
40 <module>mod_proxy</module>
41 </modulelist>
42 <directivelist>
43 <directive type="section" module="core">Directory</directive>
44 <directive type="section" module="core">DirectoryMatch</directive>
45 <directive type="section" module="core">Files</directive>
46 <directive type="section" module="core">FilesMatch</directive>
47 <directive type="section" module="core">IfDefine</directive>
48 <directive type="section" module="core">IfModule</directive>
49 <directive type="section" module="mod_version">IfVersion</directive>
50 <directive type="section" module="core">Location</directive>
51 <directive type="section" module="core">LocationMatch</directive>
52 <directive type="section" module="mod_proxy">Proxy</directive>
53 <directive type="section" module="mod_proxy">ProxyMatch</directive>
54 <directive type="section" module="core">VirtualHost</directive>
55 </directivelist>
56 </related>
57
58 <p>コンテナには二つの基本となる種類があります。ほとんどのコンテナは
59 各リクエストに対して評価されます。その場合、コンテナ中のディレクティブは
60 コンテナにマッチするリクエストにのみ適用されます。一方、
61 <directive type="section" module="core">IfDefine</directive>, 
62 <directive type="section" module="core">IfModule</directive>, 
63 <directive type="section" module="mod_version">IfVersion</directive>
64 コンテナは
65 サーバの起動時と再起動時にのみ評価されます。起動時に条件が真であれば、
66 コンテナ中のディレクティブはすべてのリクエストに適用されます。条件が
67 偽であれば、コンテナ中のディレクティブは無視されます。</p>
68
69 <p><directive type="section" module="core">IfDefine</directive> ディレクティブは
70 <program>httpd</program> コマンドラインで適切なパラメータが定義されたときにのみ
71 適用されるディレクティブを囲います。例えば次の設定では、サーバが
72 <code>httpd -DClosedForNow</code> を使って起動されたときだけすべての
73 リクエストを別のサイトにリダイレクトします:</p>
74
75 <example>
76 &lt;IfDefine ClosedForNow&gt;<br />
77 Redirect / http://otherserver.example.com/<br />
78 &lt;/IfDefine&gt;
79 </example>
80
81 <p><directive type="section" module="core">IfModule</directive> は
82 非常に似ていますが、代わりにサーバ上でモジュールが使用可能な場合にのみ
83 適用可能なディレクティブを囲います。モジュールはサーバに
84 静的に組み込まれているか、動的に組み込むようになっていて、設定ファイル中で
85 <directive module="mod_so">LoadModule</directive> の行がより前の
86 部分に書かれている必要があります。このディレクティブは特定のモジュールの
87 存在に関わらず設定ファイルが動作する必要がある場合にのみ使ってください。
88 常に動作して欲しいディレクティブを囲むために使うべきではありません。
89 存在しないモジュールに関する有用なエラーメッセージの発生を抑制してしまいますので。
90 </p>
91
92 <p>次の例では、<module>mod_mime_magic</module> があるときにのみ <directive
93 module="mod_mime_magic">MimeMagicFiles</directive> ディレクティブが
94 適用されます。</p>
95
96 <example>
97 &lt;IfModule mod_mime_magic.c&gt;<br />
98 MimeMagicFile conf/magic<br />
99 &lt;/IfModule&gt;
100 </example>
101
102 <p><directive type="section" module="mod_version">IfVersion</directive>
103 ディレクティブは
104 <directive type="section" module="core">IfDefine</directive> や
105 <directive type="section" module="core">IfModule</directive>と、
106 とてもよく似ていますが、稼働中のサーバのバージョンが特定のバージョンの時にのみ
107 適用されます。様々なバージョンの httpd を様々な設定で動作させることになる場合で、
108 テストスイートや巨大なネットワークでの用途を想定して、
109 このモジュールは設計されています。</p>
110
111 <example>
112   &lt;IfVersion >= 2.1&gt;<br />
113   <indent>
114     # this happens only in versions greater or<br />
115     # equal 2.1.0.<br />
116   </indent>
117   &lt;/IfVersion&gt;
118 </example>
119
120 <p><directive type="section" module="core">IfDefine</directive>, 
121 <directive type="section" module="core">IfModule</directive>,
122 <directive type="section" module="mod_version">IfVersion</directive> ディレクティブは
123 テストの前に "!" を付けることで否定の条件を適用することができます。
124 また、これらのセクションはより複雑な制限を課すために入れ子にすることができます。
125 </p>
126 </section>
127
128 <section id="file-and-web"><title>ファイルシステムとウェブ空間</title>
129
130 <p>最もよく使われる設定のセクションコンテナはファイルシステムやウェブ空間の
131 特定の場所の設定を変更するものです。まず、この二つの違いを理解することが
132 大切です。ファイルシステムはオペレーティングシステムから見たディスクの内容です。
133 たとえば、デフォルトのインストールでは Apache は Unix ファイルシステムでは
134 <code>/usr/local/apache2</code> に、Windows ファイルシステムでは
135 <code>"c:/Program Files/Apache Group/Apache2"</code> に存在します。
136 (Apache では Windows でもパスセパレータとしてスラッシュを使うことに
137 気をつけてください。) 対照的に、ウェブ空間はあなたのサイトを
138 ウェブサーバから配信されるものとして見たもので、クライアントに見えるものです。
139 デフォルトの Unix 上の Apache のインストールではウェブ空間の
140 <code>/dir/</code> というパスはファイルシステムの
141 <code>/usr/local/apache2/htdocs/dir/</code> というパスに対応します。
142 ウェブページはデータベースや他の場所から動的に生成することもできますので、
143 ウェブ空間はファイルシステムに直接マップする必要はありません。</p>
144
145 <section id="filesystem"><title>ファイルシステムコンテナ</title>
146
147 <p><directive type="section" module="core">Directory</directive> ディレクティブと
148 <directive type="section" module="core">Files</directive> ディレクティブ、それと
149 それらの正規表現版はディレクティブをファイルシステムの一部分に対して適用します。
150 <directive type="section" module="core">Directory</directive> セクションの
151 中のディレクティブは指定されたディレクトリとそのすべてのサブディレクトリに
152 適用されます。<a href="howto/htaccess.html">.htaccess ファイル</a>を
153 使うことでも同じ効果を得ることができます。例えば、次の設定では
154 <code>/var/web/dir1</code> とすべてのサブディレクトリに対して
155 ディレクトリインデックスを行ないます。</p>
156
157 <example>
158 &lt;Directory /var/web/dir1&gt;<br />
159 Options +Indexes<br />
160 &lt;/Directory&gt;
161 </example>
162
163 <p><directive type="section" module="core">Files</directive> セクションの
164 中にあるディレクティブはどのディレクトリにあるかに関わらず、指定された名前の
165 すべてのファイルに適用されます。ですから例えば以下の設定ディレクティブが
166 設定ファイルの主セクションに書かれたときには、すべての場所の
167 <code>private.html</code> という名前のファイルへのアクセスを拒否します。</p>
168
169 <example>
170 &lt;Files private.html&gt;<br />
171 Order allow,deny<br />
172 Deny from all<br />
173 &lt;/Files&gt;
174 </example>
175
176 <p>ファイルシステムの特定の場所にあるファイルを指定するために、
177 <directive type="section" module="core">Files</directive> セクションと
178 <directive type="section" module="core">Directory</directive> セクションを
179 組み合わせることができます。例えば、次の設定では
180 <code>/var/web/dir1/private.html</code>, 
181 <code>/var/web/dir1/subdir2/private.html</code>, 
182 <code>/var/web/dir1/subdir3/private.html</code> など、
183 <code>/var/web/dir1/</code> ディレクトリの下にあるすべての
184 <code>private.html</code> へのアクセスを拒否します。</p>
185
186 <example>
187 &lt;Directory /var/web/dir1&gt;<br />
188 &lt;Files private.html&gt;<br />
189 Order allow,deny<br />
190 Deny from all<br />
191 &lt;/Files&gt;<br />
192 &lt;/Directory&gt;
193 </example>
194 </section>
195
196 <section id="webspace"><title>ウェブ空間コンテナ</title>
197
198 <p>一方、<directive type="section" module="core">Location</directive>
199 ディレクティブとその<glossary ref="regex">正規表現</glossary>版は
200 ウェブ空間上の内容に対して設定を変更します。
201 たとえば、次の設定では /private で始まる URL パスへのアクセスを制限します。
202 具体的には、
203 <code>http://yoursite.example.com/private</code>,
204 <code>http://yoursite.example.com/private123</code>, 
205 <code>http://yoursite.example.com/private/dir/file.html</code> 
206 へのリクエストや、
207 他の同様に <code>/private</code> 文字列で始まるリクエストに
208 適用されます。</p>
209
210 <example>
211 &lt;Location /private&gt;<br />
212 Order Allow,Deny<br />
213 Deny from all<br />
214 &lt;/Location&gt;
215 </example>
216
217 <p><directive type="section" module="core">Location</directive>
218 ディレクティブはファイルシステムと関係ある必要が全くありません。
219 たとえば次の例では、どのようにして特定の URL を
220 <module>mod_status</module>で提供されている Apache 
221 内部ハンドラにマップするかを示しています。ファイルシステムに
222 <code>server-status</code> というファイルが存在する必要はありません。</p>
223
224 <example>
225 &lt;Location /server-status&gt;<br />
226 SetHandler server-status<br />
227 &lt;/Location&gt;
228 </example>
229 </section>
230
231 <section id="wildcards"><title>ワイルドカードと正規表現</title>
232
233 <p><directive type="section" module="core">Directory</directive>, 
234 <directive type="section" module="core">Files</directive>, 
235 <directive type="section" module="core">Location</directive> 
236 ディレクティブでは、 C 標準ライブラリの <code>fnmatch</code> のように
237 shell スタイルのワイルドカードキャラクタが使用できます。
238 "*" 文字は任意の文字列にマッチし、"?" 文字は任意の 1 文字にマッチし、
239 "[<em>seq</em>]" は <em>seq</em> の任意の文字にマッチします。
240 "/" 文字はどのワイルドカードでもマッチされません。
241 明示的に指定する必要があります。</p>
242
243 <p>これより柔軟なマッチングが必要な場合は、これらのコンテナに正規表現
244 (regex) 版である
245 <directive type="section" module="core">DirectoryMatch</directive>, 
246 <directive type="section" module="core">FilesMatch</directive>, 
247 <directive type="section" module="core">LocationMatch</directive>
248 があり、マッチを選択するのに perl 互換<glossary ref="regex"
249 >正規表現</glossary>を使用できます。しかし、次の設定のマージに目を通して、
250 regex セクションを使用することで、ディレクティブの適用がどのように
251 変化するか把握しておいてください。</p>
252
253 <p>全ユーザディレクトリの設定を変更する、非 regex
254 ワイルドカードセクションは次のようになります。</p>
255
256 <example>
257 &lt;Directory /home/*/public_html&gt;<br />
258 Options Indexes<br />
259 &lt;/Directory&gt;
260 </example>
261
262 <p>regex セクションを使用することで、画像ファイルの多くのタイプに対する
263 アクセスを一度に拒否できます。</p>
264 <example>
265 &lt;FilesMatch \.(?i:gif|jpe?g|png)$&gt;<br />
266 Order allow,deny<br />
267 Deny from all<br />
268 &lt;/FilesMatch&gt;
269 </example>
270
271 </section>
272
273 <section id="whichwhen"><title>いつ何を使うか</title>
274
275 <p>ファイルシステムコンテナとウェブ空間コンテナを使い分けるのは、
276 実際には非常に簡単です。ファイルシステムに依存する
277 オブジェクトにディレクティブを適応する場合は、必ず
278 <directive type="section" module="core">Directory</directive> か
279 <directive type="section" module="core">Files</directive>
280 を使用します。ファイルシステムに依存しないオブジェクト
281 (データベースから生成されるウェブページなど) 
282 にディレクティブを適用する際には、
283 <directive type="section" module="core">Location</directive>
284 を使用します。</p>
285
286 <p>ファイルシステム上のオブジェクトへのアクセスを制限するために、
287 <directive type="section" module="core">Location</directive>
288 を決して使用ないようにしましょう。
289 同一のファイルシステム位置にマップしている、ウェブ空間位置 (URL)
290 が多数あって、設定した制限を迂回されてしまうかもしれないからです。
291 例えば次の設定を考えてみましょう。</p>
292
293 <example>
294 &lt;Location /dir/&gt;<br />
295 Order allow,deny<br />
296 Deny from all<br />
297 &lt;/Location&gt;
298 </example>
299
300 <p><code>http://yoursite.example.com/dir/</code>
301 へのリクエストでは上手く動作します。しかし大文字小文字を区別しない
302 ファイルシステムを使っていたらどうなるでしょう?
303 <code>http://yoursite.example.com/DIR/</code> 
304 へのリクエストで簡単にアクセス制限を迂回されてしまいます。これに対して
305 <directive type="section" module="core">Directory</directive>
306 ディレクティブを使用すると、どのように呼び出されたかに関わらず
307 その場所から提供される内容に適用されます。
308 (例外はファイルシステムのリンクです。シンボリックリンクを使って、
309 同一のディレクトリを複数のファイルシステムに設置できます。
310 <directive type="section" module="core">Directory</directive>
311 ディレクティブはパス名をリセットすることなくシンボリックリンクを
312 辿ります。ですから、高度なセキュリティが要求される場合は、
313 適切に <directive module="core">Options</directive> 
314 ディレクティブを使用してシンボリックリンクを無効にするべきです。)</p>
315
316 <p>大文字小文字を区別するファイルシステムを使用しているから上記のことは
317 無関係だと思われるかもしれませんが、
318 同一のファイルシステム位置に複数のウェブ空間位置をマップする方法は、
319 他にいくらでもあるということを覚えていてください。
320 ですからできる限りファイルシステムコンテナを使用してください。
321 しかしながら一つだけ例外があります。
322 <code>&lt;Location /&gt;</code> セクションはどんな URL 
323 にも関わらず適用されるので、完全に安全です。</p>
324 </section>
325
326 </section>
327
328 <section id="virtualhost"><title>バーチャルホスト</title>
329
330 <p><directive type="section" module="core">VirtualHost</directive>
331 コンテナは特定のホストに適用するディレクティブを格納します。
332 一台のマシンで複数のホストを異なる設定で提供したいときに有用です。
333 詳細に関しては<a href="vhosts/">バーチャルホストドキュメント</a>を
334 ご覧下さい。</p>
335 </section>
336
337 <section id="proxy"><title>プロクシ</title>
338
339 <p><directive type="section" module="mod_proxy">Proxy</directive>
340 と <directive type="section" module="mod_proxy">ProxyMatch</directive>
341 コンテナは、特定の URL にマッチする <module>mod_proxy</module>
342 プロクシサーバを経由してアクセスしたサイトに対してのみ適用される
343 設定ディレクティブを格納します。例えば次の設定は、<code>cnn.com</code> 
344 ウェブサイトにアクセスするために用いられるプロクシサーバを
345 制限します。</p>
346
347 <example>
348 &lt;Proxy http://cnn.com/*&gt;<br />
349 Order allow,deny<br />
350 Deny from all<br />
351 &lt;/Proxy&gt;
352 </example>
353 </section>
354
355 <section id="whatwhere"><title>どのディレクティブが使えるの?</title>
356
357 <p>どのタイプの設定セクションでどのディレクティブが使用できるかは、
358 ディレクティブの <a href="mod/directive-dict.html#Context">Context</a>
359 を見てください。
360 <directive type="section" module="core">Directory</directive>
361 で使用可能なものは全て、同様に
362 <directive type="section" module="core">DirectoryMatch</directive>,
363 <directive type="section" module="core">Files</directive>,
364 <directive type="section" module="core">FilesMatch</directive>,
365 <directive type="section" module="core">Location</directive>,
366 <directive type="section" module="core">LocationMatch</directive>,
367 <directive type="section" module="mod_proxy">Proxy</directive>,
368 <directive type="section" module="mod_proxy">ProxyMatch</directive>
369 セクションで使用可能です。しかしながら幾つか例外も存在します。</p>
370
371 <ul>
372 <li><directive module="core">AllowOverride</directive> ディレクティブは
373 <directive type="section" module="core">Directory</directive>
374 セクションでのみ使用可能です。</li>
375
376 <li><code>FollowSymLinks</code> と <code>SymLinksIfOwnerMatch</code> の
377 <directive module="core">Options</directive> は、
378 <directive type="section" module="core">Directory</directive>
379 セクションか <code>.htaccess</code> ファイルでのみ使用可能です。</li>
380
381 <li><directive module="core">Options</directive> ディレクティブは、
382 <directive type="section" module="core">Files</directive>
383 と <directive type="section" module="core">FilesMatch</directive>
384 セクションでは使用できません。</li>
385 </ul>
386 </section>
387
388 <section id="mergin"><title>セクションのマージ方法</title>
389
390     <p>マージの順番は以下のようになっています:</p>
391
392     <ol>
393       <li><directive
394       type="section" module="core">Directory</directive> (正規表現無し) と
395       <code>.htaccess</code> を同時に (<code>.htaccess</code> が許可されていれば、それが
396       <directive type="section" module="core">Directory</directive> を上書きします)
397       </li>
398
399       <li><directive type="section" module="core">DirectoryMatch</directive>
400       (と <code>&lt;Directory ~&gt;</code></li>
401
402       <li><directive type="section" module="core">Files</directive> と
403       <directive type="section" module="core">FilesMatch</directive> を同時に</li>
404
405       <li><directive type="section" module="core">Location</directive> と
406       <directive type="section" module="core">LocationMatch</directive> を同時に</li>
407     </ol>
408
409     <p><directive type="section" module="core">Directory</directive>
410     以外は、それぞれのグループは設定ファイルに現れた順番に処理されます。
411     <directive type="section" module="core">Directory</directive> (上のグループ 1)
412     はディレクトリが短いものから長いものへと処理されます。ですから、
413     例えば <code>&lt;Directory /var/web/dir1&gt;</code> は
414     <code>&lt;Directory /var/web/dir/subdir&gt;</code> の前に処理されます。複数の
415     <directive
416     type="section" module="core">Directory</directive> セクションが
417     同じディレクトリに
418     適用される場合は、設定ファイル中の順番に従って処理されます。
419     <directive module="core">Include</directive>
420     によって挿入された設定は 挿入しているファイルの
421     <directive module="core">Include</directive>
422     ディレクティブの位置にあったかのように扱われます。</p>
423
424     <p><directive type="section"
425     module="core">VirtualHost</directive> セクション中のセクションは
426     バーチャルホストの定義の外側の対応するセクションの
427     <em>後</em>に適用されます。これによりバーチャルホストが
428     メインのサーバ設定を上書きできるようなります。</p>
429
430     <p><module>mod_proxy</module> でリクエストが処理される場合は、
431     処理順番のうち、<directive module="core" 
432     type="section">Directory</directive> コンテナの部分が
433     <directive module="mod_proxy" type="section">Proxy</directive>
434     コンテナに取って代わられます。</p>
435
436     <p>後のセクションのディレクティブが前のセクションのものを上書きします。</p>
437
438
439 <note><title>技術メモ</title>
440       実際には、名前を変換する段階 (URL
441       をファイル名にマップするために <code>Alias</code> や
442       <code>DocumentRoot</code> が使用されるところ) の直前に
443       <directive type="section" module="core">Location</directive>/<directive type="section" module="core">LocationMatch</directive>
444       が行なわれます。
445       これらを適用した結果は変換が終わった後に完全に捨てられます。
446 </note>
447 <section id="merge-examples"><title>例</title>
448
449 <p>次はマージの順番を示すための恣意的な例になっています。
450 リクエスト全てに適用されるとして、本例のディレクティブは
451 A &gt; B &gt; C &gt; D &gt; E の順番に適用されます。</p>
452
453 <example>
454 &lt;Location /&gt;<br />
455 E<br />
456 &lt;/Location&gt;<br />
457 <br />
458 &lt;Files f.html&gt;<br />
459 D<br />
460 &lt;/Files&gt;<br />
461 <br />
462 &lt;VirtualHost *&gt;<br />
463 &lt;Directory /a/b&gt;<br />
464 B<br />
465 &lt;/Directory&gt;<br />
466 &lt;/VirtualHost&gt;<br />
467 <br />
468 &lt;DirectoryMatch "^.*b$"&gt;<br />
469 C<br />
470 &lt;/DirectoryMatch&gt;<br />
471 <br />
472 &lt;Directory /a/b&gt;<br />
473 A<br />
474 &lt;/Directory&gt;<br />
475 <br />
476 </example>
477
478 <p>もっと具体的な、次の例を考えてみましょう。
479 <directive module="core" type="section">Directory</directive> 
480 セクションに設置されたアクセス制限に関わらず、
481 <directive module="core" type="section">Location</directive>
482 セクションが最後に評価されて、サーバへのアクセスは制限されません。
483 言い換えれば、マージの順番は重要で、注意して使用してください!</p>
484
485 <example>
486 &lt;Location /&gt;<br />
487 Order deny,allow<br />
488 Allow from all<br />
489 &lt;/Location&gt;<br />
490 <br />
491 # Woops!  This &lt;Directory&gt; section will have no effect<br />
492 &lt;Directory /&gt;<br />
493 Order allow,deny<br />
494 Allow from all<br />
495 Deny from badguy.example.com<br />
496 &lt;/Directory&gt;
497 </example>
498
499 </section>
500
501 </section>
502 </manualpage>