summaryrefslogtreecommitdiff
path: root/docs/manual/sections.xml.ja
blob: 7ce77d7634768884e0fa5a0ae57ae6b832fabca1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE manualpage SYSTEM "./style/manualpage.dtd">
<?xml-stylesheet type="text/xsl" href="./style/manual.ja.xsl"?>
<!-- English Revision: 420990:1333093 (outdated) -->

<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<manualpage metafile="sections.xml.meta">

<title>セクションの設定</title>

<summary> <p><a href="configuring.html">設定ファイル</a>中のディレクティブは
サーバ全体に適用されたり、特定のディレクトリやファイル、ホスト、URL にのみ
適用されるように制限したりすることができます。この文書は設定用のセクションの
コンテナや <code>.htaccess</code> ファイルを使って他の設定ディレクティブの
スコープを変更する方法を説明します。</p>
</summary>

<section id="types"><title>設定用セクションコンテナの種類</title>

<related>
<modulelist>
<module>core</module>
<module>mod_version</module>
<module>mod_proxy</module>
</modulelist>
<directivelist>
<directive type="section" module="core">Directory</directive>
<directive type="section" module="core">DirectoryMatch</directive>
<directive type="section" module="core">Files</directive>
<directive type="section" module="core">FilesMatch</directive>
<directive type="section" module="core">IfDefine</directive>
<directive type="section" module="core">IfModule</directive>
<directive type="section" module="mod_version">IfVersion</directive>
<directive type="section" module="core">Location</directive>
<directive type="section" module="core">LocationMatch</directive>
<directive type="section" module="mod_proxy">Proxy</directive>
<directive type="section" module="mod_proxy">ProxyMatch</directive>
<directive type="section" module="core">VirtualHost</directive>
</directivelist>
</related>

<p>コンテナには二つの基本となる種類があります。ほとんどのコンテナは
各リクエストに対して評価されます。その場合、コンテナ中のディレクティブは
コンテナにマッチするリクエストにのみ適用されます。一方、
<directive type="section" module="core">IfDefine</directive>, 
<directive type="section" module="core">IfModule</directive>, 
<directive type="section" module="mod_version">IfVersion</directive>
コンテナは
サーバの起動時と再起動時にのみ評価されます。起動時に条件が真であれば、
コンテナ中のディレクティブはすべてのリクエストに適用されます。条件が
偽であれば、コンテナ中のディレクティブは無視されます。</p>

<p><directive type="section" module="core">IfDefine</directive> ディレクティブは
<program>httpd</program> コマンドラインで適切なパラメータが定義されたときにのみ
適用されるディレクティブを囲います。例えば次の設定では、サーバが
<code>httpd -DClosedForNow</code> を使って起動されたときだけすべての
リクエストを別のサイトにリダイレクトします:</p>

<example>
&lt;IfDefine ClosedForNow&gt;<br />
Redirect / http://otherserver.example.com/<br />
&lt;/IfDefine&gt;
</example>

<p><directive type="section" module="core">IfModule</directive> は
非常に似ていますが、代わりにサーバ上でモジュールが使用可能な場合にのみ
適用可能なディレクティブを囲います。モジュールはサーバに
静的に組み込まれているか、動的に組み込むようになっていて、設定ファイル中で
<directive module="mod_so">LoadModule</directive> の行がより前の
部分に書かれている必要があります。このディレクティブは特定のモジュールの
存在に関わらず設定ファイルが動作する必要がある場合にのみ使ってください。
常に動作して欲しいディレクティブを囲むために使うべきではありません。
存在しないモジュールに関する有用なエラーメッセージの発生を抑制してしまいますので。
</p>

<p>次の例では、<module>mod_mime_magic</module> があるときにのみ <directive
module="mod_mime_magic">MimeMagicFiles</directive> ディレクティブが
適用されます。</p>

<example>
&lt;IfModule mod_mime_magic.c&gt;<br />
MimeMagicFile conf/magic<br />
&lt;/IfModule&gt;
</example>

<p><directive type="section" module="mod_version">IfVersion</directive>
ディレクティブは
<directive type="section" module="core">IfDefine</directive> や
<directive type="section" module="core">IfModule</directive>と、
とてもよく似ていますが、稼働中のサーバのバージョンが特定のバージョンの時にのみ
適用されます。様々なバージョンの httpd を様々な設定で動作させることになる場合で、
テストスイートや巨大なネットワークでの用途を想定して、
このモジュールは設計されています。</p>

<example>
  &lt;IfVersion >= 2.1&gt;<br />
  <indent>
    # this happens only in versions greater or<br />
    # equal 2.1.0.<br />
  </indent>
  &lt;/IfVersion&gt;
</example>

<p><directive type="section" module="core">IfDefine</directive>, 
<directive type="section" module="core">IfModule</directive>,
<directive type="section" module="mod_version">IfVersion</directive> ディレクティブは
テストの前に "!" を付けることで否定の条件を適用することができます。
また、これらのセクションはより複雑な制限を課すために入れ子にすることができます。
</p>
</section>

<section id="file-and-web"><title>ファイルシステムとウェブ空間</title>

<p>最もよく使われる設定のセクションコンテナはファイルシステムやウェブ空間の
特定の場所の設定を変更するものです。まず、この二つの違いを理解することが
大切です。ファイルシステムはオペレーティングシステムから見たディスクの内容です。
たとえば、デフォルトのインストールでは Apache は Unix ファイルシステムでは
<code>/usr/local/apache2</code> に、Windows ファイルシステムでは
<code>"c:/Program Files/Apache Group/Apache2"</code> に存在します。
(Apache では Windows でもパスセパレータとしてスラッシュを使うことに
気をつけてください。) 対照的に、ウェブ空間はあなたのサイトを
ウェブサーバから配信されるものとして見たもので、クライアントに見えるものです。
デフォルトの Unix 上の Apache のインストールではウェブ空間の
<code>/dir/</code> というパスはファイルシステムの
<code>/usr/local/apache2/htdocs/dir/</code> というパスに対応します。
ウェブページはデータベースや他の場所から動的に生成することもできますので、
ウェブ空間はファイルシステムに直接マップする必要はありません。</p>

<section id="filesystem"><title>ファイルシステムコンテナ</title>

<p><directive type="section" module="core">Directory</directive> ディレクティブと
<directive type="section" module="core">Files</directive> ディレクティブ、それと
それらの正規表現版はディレクティブをファイルシステムの一部分に対して適用します。
<directive type="section" module="core">Directory</directive> セクションの
中のディレクティブは指定されたディレクトリとそのすべてのサブディレクトリに
適用されます。<a href="howto/htaccess.html">.htaccess ファイル</a>を
使うことでも同じ効果を得ることができます。例えば、次の設定では
<code>/var/web/dir1</code> とすべてのサブディレクトリに対して
ディレクトリインデックスを行ないます。</p>

<example>
&lt;Directory /var/web/dir1&gt;<br />
Options +Indexes<br />
&lt;/Directory&gt;
</example>

<p><directive type="section" module="core">Files</directive> セクションの
中にあるディレクティブはどのディレクトリにあるかに関わらず、指定された名前の
すべてのファイルに適用されます。ですから例えば以下の設定ディレクティブが
設定ファイルの主セクションに書かれたときには、すべての場所の
<code>private.html</code> という名前のファイルへのアクセスを拒否します。</p>

<example>
&lt;Files private.html&gt;<br />
Order allow,deny<br />
Deny from all<br />
&lt;/Files&gt;
</example>

<p>ファイルシステムの特定の場所にあるファイルを指定するために、
<directive type="section" module="core">Files</directive> セクションと
<directive type="section" module="core">Directory</directive> セクションを
組み合わせることができます。例えば、次の設定では
<code>/var/web/dir1/private.html</code>, 
<code>/var/web/dir1/subdir2/private.html</code>, 
<code>/var/web/dir1/subdir3/private.html</code> など、
<code>/var/web/dir1/</code> ディレクトリの下にあるすべての
<code>private.html</code> へのアクセスを拒否します。</p>

<example>
&lt;Directory /var/web/dir1&gt;<br />
&lt;Files private.html&gt;<br />
Order allow,deny<br />
Deny from all<br />
&lt;/Files&gt;<br />
&lt;/Directory&gt;
</example>
</section>

<section id="webspace"><title>ウェブ空間コンテナ</title>

<p>一方、<directive type="section" module="core">Location</directive>
ディレクティブとその<glossary ref="regex">正規表現</glossary>版は
ウェブ空間上の内容に対して設定を変更します。
たとえば、次の設定では /private で始まる URL パスへのアクセスを制限します。
具体的には、
<code>http://yoursite.example.com/private</code>,
<code>http://yoursite.example.com/private123</code>, 
<code>http://yoursite.example.com/private/dir/file.html</code> 
へのリクエストや、
他の同様に <code>/private</code> 文字列で始まるリクエストに
適用されます。</p>

<example>
&lt;Location /private&gt;<br />
Order Allow,Deny<br />
Deny from all<br />
&lt;/Location&gt;
</example>

<p><directive type="section" module="core">Location</directive>
ディレクティブはファイルシステムと関係ある必要が全くありません。
たとえば次の例では、どのようにして特定の URL を
<module>mod_status</module>で提供されている Apache 
内部ハンドラにマップするかを示しています。ファイルシステムに
<code>server-status</code> というファイルが存在する必要はありません。</p>

<example>
&lt;Location /server-status&gt;<br />
SetHandler server-status<br />
&lt;/Location&gt;
</example>
</section>

<section id="wildcards"><title>ワイルドカードと正規表現</title>

<p><directive type="section" module="core">Directory</directive>, 
<directive type="section" module="core">Files</directive>, 
<directive type="section" module="core">Location</directive> 
ディレクティブでは、 C 標準ライブラリの <code>fnmatch</code> のように
shell スタイルのワイルドカードキャラクタが使用できます。
"*" 文字は任意の文字列にマッチし、"?" 文字は任意の 1 文字にマッチし、
"[<em>seq</em>]" は <em>seq</em> の任意の文字にマッチします。
"/" 文字はどのワイルドカードでもマッチされません。
明示的に指定する必要があります。</p>

<p>これより柔軟なマッチングが必要な場合は、これらのコンテナに正規表現
(regex) 版である
<directive type="section" module="core">DirectoryMatch</directive>, 
<directive type="section" module="core">FilesMatch</directive>, 
<directive type="section" module="core">LocationMatch</directive>
があり、マッチを選択するのに perl 互換<glossary ref="regex"
>正規表現</glossary>を使用できます。しかし、次の設定のマージに目を通して、
regex セクションを使用することで、ディレクティブの適用がどのように
変化するか把握しておいてください。</p>

<p>全ユーザディレクトリの設定を変更する、非 regex
ワイルドカードセクションは次のようになります。</p>

<example>
&lt;Directory /home/*/public_html&gt;<br />
Options Indexes<br />
&lt;/Directory&gt;
</example>

<p>regex セクションを使用することで、画像ファイルの多くのタイプに対する
アクセスを一度に拒否できます。</p>
<example>
&lt;FilesMatch \.(?i:gif|jpe?g|png)$&gt;<br />
Order allow,deny<br />
Deny from all<br />
&lt;/FilesMatch&gt;
</example>

</section>

<section id="whichwhen"><title>いつ何を使うか</title>

<p>ファイルシステムコンテナとウェブ空間コンテナを使い分けるのは、
実際には非常に簡単です。ファイルシステムに依存する
オブジェクトにディレクティブを適応する場合は、必ず
<directive type="section" module="core">Directory</directive> か
<directive type="section" module="core">Files</directive>
を使用します。ファイルシステムに依存しないオブジェクト
(データベースから生成されるウェブページなど) 
にディレクティブを適用する際には、
<directive type="section" module="core">Location</directive>
を使用します。</p>

<p>ファイルシステム上のオブジェクトへのアクセスを制限するために、
<directive type="section" module="core">Location</directive>
を決して使用ないようにしましょう。
同一のファイルシステム位置にマップしている、ウェブ空間位置 (URL)
が多数あって、設定した制限を迂回されてしまうかもしれないからです。
例えば次の設定を考えてみましょう。</p>

<example>
&lt;Location /dir/&gt;<br />
Order allow,deny<br />
Deny from all<br />
&lt;/Location&gt;
</example>

<p><code>http://yoursite.example.com/dir/</code>
へのリクエストでは上手く動作します。しかし大文字小文字を区別しない
ファイルシステムを使っていたらどうなるでしょう?
<code>http://yoursite.example.com/DIR/</code> 
へのリクエストで簡単にアクセス制限を迂回されてしまいます。これに対して
<directive type="section" module="core">Directory</directive>
ディレクティブを使用すると、どのように呼び出されたかに関わらず
その場所から提供される内容に適用されます。
(例外はファイルシステムのリンクです。シンボリックリンクを使って、
同一のディレクトリを複数のファイルシステムに設置できます。
<directive type="section" module="core">Directory</directive>
ディレクティブはパス名をリセットすることなくシンボリックリンクを
辿ります。ですから、高度なセキュリティが要求される場合は、
適切に <directive module="core">Options</directive> 
ディレクティブを使用してシンボリックリンクを無効にするべきです。)</p>

<p>大文字小文字を区別するファイルシステムを使用しているから上記のことは
無関係だと思われるかもしれませんが、
同一のファイルシステム位置に複数のウェブ空間位置をマップする方法は、
他にいくらでもあるということを覚えていてください。
ですからできる限りファイルシステムコンテナを使用してください。
しかしながら一つだけ例外があります。
<code>&lt;Location /&gt;</code> セクションはどんな URL 
にも関わらず適用されるので、完全に安全です。</p>
</section>

</section>

<section id="virtualhost"><title>バーチャルホスト</title>

<p><directive type="section" module="core">VirtualHost</directive>
コンテナは特定のホストに適用するディレクティブを格納します。
一台のマシンで複数のホストを異なる設定で提供したいときに有用です。
詳細に関しては<a href="vhosts/">バーチャルホストドキュメント</a>を
ご覧下さい。</p>
</section>

<section id="proxy"><title>プロクシ</title>

<p><directive type="section" module="mod_proxy">Proxy</directive>
と <directive type="section" module="mod_proxy">ProxyMatch</directive>
コンテナは、特定の URL にマッチする <module>mod_proxy</module>
プロクシサーバを経由してアクセスしたサイトに対してのみ適用される
設定ディレクティブを格納します。例えば次の設定は、<code>cnn.com</code> 
ウェブサイトにアクセスするために用いられるプロクシサーバを
制限します。</p>

<example>
&lt;Proxy http://cnn.com/*&gt;<br />
Order allow,deny<br />
Deny from all<br />
&lt;/Proxy&gt;
</example>
</section>

<section id="whatwhere"><title>どのディレクティブが使えるの?</title>

<p>どのタイプの設定セクションでどのディレクティブが使用できるかは、
ディレクティブの <a href="mod/directive-dict.html#Context">Context</a>
を見てください。
<directive type="section" module="core">Directory</directive>
で使用可能なものは全て、同様に
<directive type="section" module="core">DirectoryMatch</directive>,
<directive type="section" module="core">Files</directive>,
<directive type="section" module="core">FilesMatch</directive>,
<directive type="section" module="core">Location</directive>,
<directive type="section" module="core">LocationMatch</directive>,
<directive type="section" module="mod_proxy">Proxy</directive>,
<directive type="section" module="mod_proxy">ProxyMatch</directive>
セクションで使用可能です。しかしながら幾つか例外も存在します。</p>

<ul>
<li><directive module="core">AllowOverride</directive> ディレクティブは
<directive type="section" module="core">Directory</directive>
セクションでのみ使用可能です。</li>

<li><code>FollowSymLinks</code> と <code>SymLinksIfOwnerMatch</code> の
<directive module="core">Options</directive> は、
<directive type="section" module="core">Directory</directive>
セクションか <code>.htaccess</code> ファイルでのみ使用可能です。</li>

<li><directive module="core">Options</directive> ディレクティブは、
<directive type="section" module="core">Files</directive>
と <directive type="section" module="core">FilesMatch</directive>
セクションでは使用できません。</li>
</ul>
</section>

<section id="mergin"><title>セクションのマージ方法</title>

    <p>マージの順番は以下のようになっています:</p>

    <ol>
      <li><directive
      type="section" module="core">Directory</directive> (正規表現無し) と
      <code>.htaccess</code> を同時に (<code>.htaccess</code> が許可されていれば、それが
      <directive type="section" module="core">Directory</directive> を上書きします)
      </li>

      <li><directive type="section" module="core">DirectoryMatch</directive>
      (と <code>&lt;Directory ~&gt;</code></li>

      <li><directive type="section" module="core">Files</directive> と
      <directive type="section" module="core">FilesMatch</directive> を同時に</li>

      <li><directive type="section" module="core">Location</directive> と
      <directive type="section" module="core">LocationMatch</directive> を同時に</li>
    </ol>

    <p><directive type="section" module="core">Directory</directive>
    以外は、それぞれのグループは設定ファイルに現れた順番に処理されます。
    <directive type="section" module="core">Directory</directive> (上のグループ 1)
    はディレクトリが短いものから長いものへと処理されます。ですから、
    例えば <code>&lt;Directory /var/web/dir1&gt;</code> は
    <code>&lt;Directory /var/web/dir/subdir&gt;</code> の前に処理されます。複数の
    <directive
    type="section" module="core">Directory</directive> セクションが
    同じディレクトリに
    適用される場合は、設定ファイル中の順番に従って処理されます。
    <directive module="core">Include</directive>
    によって挿入された設定は 挿入しているファイルの
    <directive module="core">Include</directive>
    ディレクティブの位置にあったかのように扱われます。</p>

    <p><directive type="section"
    module="core">VirtualHost</directive> セクション中のセクションは
    バーチャルホストの定義の外側の対応するセクションの
    <em>後</em>に適用されます。これによりバーチャルホストが
    メインのサーバ設定を上書きできるようなります。</p>

    <p><module>mod_proxy</module> でリクエストが処理される場合は、
    処理順番のうち、<directive module="core" 
    type="section">Directory</directive> コンテナの部分が
    <directive module="mod_proxy" type="section">Proxy</directive>
    コンテナに取って代わられます。</p>

    <p>後のセクションのディレクティブが前のセクションのものを上書きします。</p>


<note><title>技術メモ</title>
      実際には、名前を変換する段階 (URL
      をファイル名にマップするために <code>Alias</code> や
      <code>DocumentRoot</code> が使用されるところ) の直前に
      <directive type="section" module="core">Location</directive>/<directive type="section" module="core">LocationMatch</directive>
      が行なわれます。
      これらを適用した結果は変換が終わった後に完全に捨てられます。
</note>
<section id="merge-examples"><title>例</title>

<p>次はマージの順番を示すための恣意的な例になっています。
リクエスト全てに適用されるとして、本例のディレクティブは
A &gt; B &gt; C &gt; D &gt; E の順番に適用されます。</p>

<example>
&lt;Location /&gt;<br />
E<br />
&lt;/Location&gt;<br />
<br />
&lt;Files f.html&gt;<br />
D<br />
&lt;/Files&gt;<br />
<br />
&lt;VirtualHost *&gt;<br />
&lt;Directory /a/b&gt;<br />
B<br />
&lt;/Directory&gt;<br />
&lt;/VirtualHost&gt;<br />
<br />
&lt;DirectoryMatch "^.*b$"&gt;<br />
C<br />
&lt;/DirectoryMatch&gt;<br />
<br />
&lt;Directory /a/b&gt;<br />
A<br />
&lt;/Directory&gt;<br />
<br />
</example>

<p>もっと具体的な、次の例を考えてみましょう。
<directive module="core" type="section">Directory</directive> 
セクションに設置されたアクセス制限に関わらず、
<directive module="core" type="section">Location</directive>
セクションが最後に評価されて、サーバへのアクセスは制限されません。
言い換えれば、マージの順番は重要で、注意して使用してください!</p>

<example>
&lt;Location /&gt;<br />
Order deny,allow<br />
Allow from all<br />
&lt;/Location&gt;<br />
<br />
# Woops!  This &lt;Directory&gt; section will have no effect<br />
&lt;Directory /&gt;<br />
Order allow,deny<br />
Allow from all<br />
Deny from badguy.example.com<br />
&lt;/Directory&gt;
</example>

</section>

</section>
</manualpage>