]> granicus.if.org Git - apache/blob - docs/manual/vhosts/examples.xml.ja
Rebuild.
[apache] / docs / manual / vhosts / examples.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:1746754 (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="examples.xml.meta">
24 <parentdocument href="./">バーチャルホスト</parentdocument>
25     <title>バーチャルホストの例</title>
26
27 <summary>
28
29     <p>この文書は、バーチャルホストの設定の際に
30     よくある質問に答えるものです。想定している対象は <a
31     href="name-based.html">名前ベース</a> や <a
32     href="ip-based.html">IP ベース</a> のバーチャルホストを使って
33     一つのサーバで複数のウェブサイトを運用している状況です。
34     </p>
35
36 </summary>
37
38   <section id="purename"><title>一つの IP アドレスでいくつかの名前ベースの
39     ウェブサイトを実行する</title>
40
41     <p>サーバは IP アドレスを一つ割り当てられていて、DNS でマシンに
42     複数の名前 (CNAME) が指定されています。このマシンで
43     <code>www.example.com</code> と <code>www.example.org</code>
44     のためのウェブサーバを実行させたいとします。</p>
45
46     <note><title>注</title><p>
47           Apache サーバの設定でバーチャルホストの設定をしただけで、
48           知らない間にそのホスト名に対応する DNS のエントリが
49           作成されたりはしません。そのサーバの IP アドレスに解決される
50           ように DNS に名前を登録しなければ<em>なりません</em>。
51           そうでないと誰もあなたのウェブサイトを見ることはできません。
52           ローカルでのテストのために <code>hosts</code> ファイルに
53           エントリを追加することもできますが、この場合はその
54           hosts エントリのあるマシンからしか動作しません。</p>
55     </note>
56
57     <example>
58     <title>サーバ設定</title>
59
60     # Ensure that Apache listens on port 80<br />
61     Listen 80<br />
62     <br />
63     # Listen for virtual host requests on all IP addresses<br />
64     NameVirtualHost *:80<br />
65     <br />
66     &lt;VirtualHost *:80&gt;<br />
67     <indent>
68       DocumentRoot /www/example1<br />
69       ServerName www.example.com<br />
70       <br />
71       # Other directives here<br />
72       <br />
73     </indent>
74     &lt;/VirtualHost&gt;<br />
75     <br />
76     &lt;VirtualHost *:80&gt;<br />
77     <indent>
78       DocumentRoot /www/example2<br />
79       ServerName www.example.org<br />
80       <br />
81       # Other directives here<br />
82       <br />
83     </indent>
84     &lt;/VirtualHost&gt;
85     </example>
86
87     <p>アスタリスクはすべてのアドレスにマッチしますので、主サーバは
88     リクエストを扱いません。<code>www.example.com</code> は
89     最初にあるため、優先順位は一番高くなり、<cite>default</cite> もしくは
90     <cite>primary</cite>  のサーバと考えることができます。つまり、リクエストが
91     どの <code>ServerName</code> ディレクティブにもマッチしない場合、
92     一番最初の <code>VirtualHost</code> により扱われます。</p>
93
94     <note><title>注</title>
95
96           <p><code>*</code> をシステムの実際の IP アドレスに置き換える
97           こともできます。その場合は <code>VirtualHost</code> の引数は
98           <code>NameVirtualHost</code> の引数と同じに<em>しなければなりません
99           </em>:</p>
100
101             <example>
102             NameVirtualHost 172.20.30.40<br />
103             <br />
104             &lt;VirtualHost 172.20.30.40&gt;<br />
105              # etc ...
106             </example>
107
108           <p>しかし、IP アドレスが予測不可能なシステム
109           ――例えばプロバイダから動的に IP アドレスを取得して何らかの
110           ダイナミック DNS を使っている場合など――においては、<code>*</code> 
111           指定はさらに便利です。<code>*</code> はすべての IP アドレスに
112           マッチしますので、この設定にしておけば IP アドレスが変更されても
113           設定変更せずに動作します。</p>
114     </note>
115
116     <p>名前ベースのバーチャルホスティングではほぼすべての状況で、
117     上記の設定で希望の設定になっていることでしょう。
118     実際この設定が動作しないのは、IP アドレスやポートの違いによって
119     違うコンテンツを送るときだけです。</p>
120
121     </section>
122
123     <section id="twoips"><title>複数の IP アドレスのあるホストで名前ベースの
124     ホスティングを行なう</title>
125  
126     <note>
127     <title>注</title><p>ここで説明されている方法は IP アドレスが
128     何個あっても同様にできます。</p>
129     </note>
130
131     <p>サーバには二つ IP アドレスがついています。一つ目
132     (<code>172.20.30.40</code>) では主サーバ 
133     <code>server.domain.com</code> を扱い、もう一方
134     (<code>172.20.30.50</code>) では二つかそれ以上の数の
135     バーチャルホストを扱います。</p>
136
137     <example>
138     <title>サーバの設定</title>
139
140     Listen 80<br />
141     <br />
142     # This is the "main" server running on 172.20.30.40<br />
143     ServerName server.domain.com<br />
144     DocumentRoot /www/mainserver<br />
145     <br />
146     # This is the other address<br />
147     NameVirtualHost 172.20.30.50<br />
148     <br />
149     &lt;VirtualHost 172.20.30.50&gt;<br />
150     <indent>
151         DocumentRoot /www/example1<br />
152         ServerName www.example.com<br />
153         <br />
154         # Other directives here ...<br />
155         <br />
156     </indent>
157     &lt;/VirtualHost&gt;<br />
158     <br />
159     &lt;VirtualHost 172.20.30.50&gt;<br />
160     <indent>
161         DocumentRoot /www/example2<br />
162         ServerName www.example.org<br />
163         <br />
164         # Other directives here ...<br />
165         <br />
166     </indent>
167     &lt;/VirtualHost&gt;
168     </example>
169
170     <p><code>172.20.30.50</code> 以外のアドレスへのリクエストは主サーバ
171     が扱います。<code>172.20.30.50</code> への、未知のホスト名または
172     <code>Host:</code> ヘッダなしのリクエストは <code>www.example.com</code>
173     が扱います。</p>
174
175     </section>
176
177     <section id="intraextra"><title>違う IP アドレス (例えば、内部と外部アドレス)
178     で同じコンテンツを送る</title>
179
180     <p>サーバマシンは IP アドレスを二つ (<code>192.168.1.1</code>
181     と <code>172.20.30.40</code>) 持っています。このマシンは内部
182     (イントラネット) と 外部 (インターネット) のネットワークの間に
183     あります。<code>server.example.com</code> はネットワークの外からは
184     外部アドレス (<code>172.20.30.40</code>) として解決されますが、
185     ネットワークの中からは内部アドレス (<code>192.168.1.1</code>) 
186     として解決されます。</p>
187
188     <p><code>VirtualHost</code> 一つだけでサーバが内部のリクエストと
189     外部のリクエストの両方に同じコンテンツで応答するようにできます。</p>
190
191     <example>
192     <title>サーバの設定</title>
193
194     NameVirtualHost 192.168.1.1<br />
195     NameVirtualHost 172.20.30.40<br />
196     <br />
197     &lt;VirtualHost 192.168.1.1 172.20.30.40&gt;<br />
198     <indent>
199         DocumentRoot /www/server1<br />
200         ServerName server.example.com<br />
201         ServerAlias server<br />
202     </indent>
203     &lt;/VirtualHost&gt;
204     </example>
205
206     <p>これでどちらのネットワークからのリクエストも同じ <code>VirtualHost</code>
207     で扱われるようになります。</p>
208
209     <note><title>注:</title><p>内部ネットワークでは完全なホスト名の
210           <code>server.example.com</code> の代わりに、単に <code>server</code>
211           を使うことができます。</p>
212
213           <p>上の例では、IP アドレスのリストを、すべてのアドレスに
214            同じコンテンツで応答する <code>*</code> に置き換えられます。</p>
215     </note>
216
217     </section>
218
219     <section id="port"><title>違うポートで違うサイトを運営する</title>
220
221     <p>同じ IP に複数のドメインがあり、さらに複数のポートを使って
222     リクエストを扱いたいときがあります。"NameVirtualHost" タグの中で
223     ポートを定義することで、これを動作させられます。
224     NameVirtualHost name:port 無しや Listen ディレクティブで
225     &lt;VirtualHost name:port&gt; を使おうとしても、その設定は動作しません。</p>
226
227     <example>
228     <title>サーバの設定</title>
229
230     Listen 80<br />
231     Listen 8080<br />
232     <br />
233     NameVirtualHost 172.20.30.40:80<br />
234     NameVirtualHost 172.20.30.40:8080<br />
235     <br />
236     &lt;VirtualHost 172.20.30.40:80&gt;<br />
237     <indent>
238         ServerName www.example.com<br />
239         DocumentRoot /www/domain-80<br />
240     </indent>
241     &lt;/VirtualHost&gt;<br />
242     <br />
243     &lt;VirtualHost 172.20.30.40:8080&gt;<br />
244     <indent>
245         ServerName www.example.com<br />
246         DocumentRoot /www/domain-8080<br />
247     </indent>
248     &lt;/VirtualHost&gt;<br />
249     <br />
250     &lt;VirtualHost 172.20.30.40:80&gt;<br />
251     <indent>
252         ServerName www.example.org<br />
253         DocumentRoot /www/otherdomain-80<br />
254     </indent>
255     &lt;/VirtualHost&gt;<br />
256     <br />
257     &lt;VirtualHost 172.20.30.40:8080&gt;<br />
258     <indent>
259         ServerName www.example.org<br />
260         DocumentRoot /www/otherdomain-8080<br />
261     </indent>
262     &lt;/VirtualHost&gt;
263     </example>
264
265     </section>
266
267     <section id="ip"><title>IP ベースのバーチャルホスティング</title>
268
269     <p>サーバは <code>www.example.com</code> と <code>www.example.org</code>
270     にそれぞれ解決される、二つの IP アドレス (<code>172.20.30.40</code> と
271     <code>172.20.30.50</code>) があります。</p>
272
273     <example>
274     <title>サーバの設定</title>
275
276     Listen 80<br />
277     <br />
278     &lt;VirtualHost 172.20.30.40&gt;<br />
279     <indent>
280         DocumentRoot /www/example1<br />
281         ServerName www.example.com<br />
282     </indent>
283     &lt;/VirtualHost&gt;<br />
284     <br />
285     &lt;VirtualHost 172.20.30.50&gt;<br />
286     <indent>
287         DocumentRoot /www/example2<br />
288         ServerName www.example.org<br />
289     </indent>
290     &lt;/VirtualHost&gt;
291     </example>
292
293     <p><code>&lt;VirtualHost&gt;</code> ディレクティブのどれでも
294     指定されていないアドレス (例えば <code>localhost</code>) は、
295     主サーバがあればそこに行きます。</p>
296
297     </section>
298
299     <section id="ipport"><title>ポートベースと IP ベースの混ざった
300     バーチャルホスト</title>
301
302     <p>サーバマシンはそれぞれ <code>www.example.com</code> と
303     <code>www.example.org</code> にそれぞれ解決される、IP アドレスを二つ
304     (<code>172.20.30.40</code> と <code>172.20.30.50</code>) 持っています。
305     どちらもポート 80 と 8080 でホストを走らせます。</p>
306
307     <example>
308     <title>サーバの設定</title>
309
310     Listen 172.20.30.40:80<br />
311     Listen 172.20.30.40:8080<br />
312     Listen 172.20.30.50:80<br />
313     Listen 172.20.30.50:8080<br />
314     <br />
315     &lt;VirtualHost 172.20.30.40:80&gt;<br />
316     <indent>
317         DocumentRoot /www/example1-80<br />
318         ServerName www.example.com<br />
319     </indent>
320     &lt;/VirtualHost&gt;<br />
321     <br />
322     &lt;VirtualHost 172.20.30.40:8080&gt;<br />
323     <indent>
324         DocumentRoot /www/example1-8080<br />
325         ServerName www.example.com<br />
326     </indent>
327     &lt;/VirtualHost&gt;<br />
328     <br />
329     &lt;VirtualHost 172.20.30.50:80&gt;<br />
330     <indent>
331         DocumentRoot /www/example2-80<br />
332         ServerName www.example.org<br />
333     </indent>
334     &lt;/VirtualHost&gt;<br />
335     <br />
336     &lt;VirtualHost 172.20.30.50:8080&gt;<br />
337     <indent>
338         DocumentRoot /www/example2-8080<br />
339         ServerName www.example.org<br />
340     </indent>
341     &lt;/VirtualHost&gt;
342     </example>
343
344     </section>
345
346     <section id="mixed"><title>名前ベースと IP ベースを混ぜた
347     バーチャルホスト</title>
348
349     <p>いくつかのマシンでは名前ベースの、その他では IP ベースのバーチャル
350     ホストをします。</p>
351
352     <example>
353     <title>サーバの設定</title>
354
355     Listen 80<br />
356     <br />
357     NameVirtualHost 172.20.30.40<br />
358     <br />
359     &lt;VirtualHost 172.20.30.40&gt;<br />
360     <indent>
361         DocumentRoot /www/example1<br />
362         ServerName www.example.com<br />
363     </indent>
364     &lt;/VirtualHost&gt;<br />
365     <br />
366     &lt;VirtualHost 172.20.30.40&gt;<br />
367     <indent>
368         DocumentRoot /www/example2<br />
369         ServerName www.example.org<br />
370     </indent>
371     &lt;/VirtualHost&gt;<br />
372     <br />
373     &lt;VirtualHost 172.20.30.40&gt;<br />
374     <indent>
375         DocumentRoot /www/example3<br />
376         ServerName www.example3.net<br />
377     </indent>
378     &lt;/VirtualHost&gt;<br />
379     <br />
380     # IP-based<br />
381     &lt;VirtualHost 172.20.30.50&gt;<br />
382     <indent>
383         DocumentRoot /www/example4<br />
384         ServerName www.example4.edu<br />
385     </indent>
386     &lt;/VirtualHost&gt;<br />
387     <br />
388     &lt;VirtualHost 172.20.30.60&gt;<br />
389     <indent>
390         DocumentRoot /www/example5<br />
391         ServerName www.example5.gov<br />
392     </indent>
393     &lt;/VirtualHost&gt;
394     </example>
395
396     </section>
397
398     <section id="proxy"><title><code>Virtual_host</code> と
399     mod_proxy を併用する</title>
400
401     <p>次の例は、フロント側のバーチャルホストで他のマシンへプロクシします。
402     例では <code>192.168.111.2</code> のマシンではバーチャルホスト名は
403     同じ名前で設定されています。複数のホスト名を一台のマシンにプロクシする
404     場合は、<directive module="mod_proxy">ProxyPreserveHost On</directive>
405     ディレクティブを使って、希望のホスト名を渡せるようになります。
406     </p>
407
408     <example>
409     &lt;VirtualHost *:*&gt;<br />
410         ProxyPreserveHost On<br />
411         ProxyPass / http://192.168.111.2/<br />
412         ProxyPassReverse / http://192.168.111.2/<br />
413         ServerName hostname.example.com<br />
414     &lt;/VirtualHost&gt;
415     </example>
416
417     </section>
418
419     <section id="default"><title><code>_default_</code> のバーチャルホストを
420     使う</title> 
421
422     <section id="defaultallports"><title>すべてのポートに対する
423     <code>_default_</code> バーチャルホスト</title>
424
425     <p>未指定の IP アドレスとポート、<em>つまり</em>他のバーチャルホストに
426     使われていないアドレスとポートの組み合わせ、への<em>すべての</em>リクエストを
427     受け取ります。</p>
428
429     <example>
430     <title>サーバの設定</title>
431
432     &lt;VirtualHost _default_:*&gt;<br />
433     <indent>
434         DocumentRoot /www/default<br />
435     </indent>
436     &lt;/VirtualHost&gt;
437     </example>
438
439     <p>このようにワイルドカードのポートでデフォルトのバーチャルホストを
440     指定すると、主サーバにリクエストが行くのを防げます。</p>
441
442     <p>デフォルトのバーチャルホストは名前ベースのバーチャルホストに
443     使われているアドレスとポートの組に送られたリクエストを扱うことは
444     ありません。リクエストが不明な <code>Host:</code> ヘッダやその
445     ヘッダがなかったりする場合は基本名前ベースバーチャルホスト (その
446     アドレスとポートで設定ファイル中で最初のバーチャルホスト) により
447     扱われます。</p>
448
449     <p>どんなリクエストでも <directive module="mod_alias">AliasMatch</directive>
450     や <directive module="mod_rewrite">RewriteRule</directive> を使って
451     単一の情報ページ (やスクリプト) に書き換えることができます。</p>
452     </section>
453
454     <section id="defaultdifferentports"><title>違うポートのための
455     <code>_default_</code> バーチャルホスト</title>
456
457     <p>一つめの設定とほぼ同じですが、サーバは複数のポートを listen しており、
458     80 番ポートに対して二つめの <code>_default_</code> バーチャルホストを
459     設定したい場合です。</p>
460
461     <example>
462     <title>サーバの設定</title>
463
464     &lt;VirtualHost _default_:80&gt;<br />
465     <indent>
466         DocumentRoot /www/default80<br />
467         # ...<br />
468     </indent>
469     &lt;/VirtualHost&gt;<br />
470     <br />
471     &lt;VirtualHost _default_:*&gt;<br />
472     <indent>
473         DocumentRoot /www/default<br />
474         # ...<br />
475     </indent>
476     &lt;/VirtualHost&gt;
477     </example>
478
479     <p>80 番ポートのデフォルトバーチャルホスト (ワイルドカードポートの
480     デフォルトバーチャルホストよりも前に書かれていなければ<em>なりません</em>) は
481     未指定の IP アドレスに送られたすべてのリクエストを扱います。
482     主サーバはリクエストを扱いません。</p>
483     </section>
484
485     <section id="defaultoneport"><title>一つのポートに対してだけの
486     <code>_default_</code> バーチャルホスト</title>
487
488     <p>80 番ポートにはデフォルトのバーチャルホストが必要で、他の
489     バーチャルホストはデフォルトが必要ない場合です。</p>
490
491     <example>
492     <title>サーバの設定</title>
493
494     &lt;VirtualHost _default_:80&gt;<br />
495     DocumentRoot /www/default<br />
496     ...<br />
497     &lt;/VirtualHost&gt;
498     </example>
499
500     <p>80 番ポートへのアドレス未指定のリクエストはデフォルトのバーチャル
501     ホストから送られます。他の未指定のアドレスとポートへのリクエストは
502     主サーバから送られます。</p>
503     </section>
504
505   </section>
506
507   <section id="migrate"><title>名前ベースのバーチャルホストから IP ベースの
508     バーチャルホストに移行する</title>
509
510     <p>ホスト名が名前 <code>www.example.org</code> のバーチャルホスト
511     (<a href="#name">名前ベース</a>の例の 2 番目の設定) が専用の IP アドレスを
512     得たとします。名前ベースのバーチャルホストの古い IP アドレスを
513     キャッシュしているネームサーバやプロキシのために移行期間中は両方の
514     バーチャルホストを提供したいとします。</p>
515
516     <p>答は簡単です。単に新しい IP アドレス (<code>172.20.30.50</code>)
517     を <code>VirtualHost</code> ディレクティブに追加することで
518     できます。</p>
519   
520     <example>
521     <title>サーバ設定</title>
522
523     Listen 80<br />
524     ServerName www.example.com<br />
525     DocumentRoot /www/example1<br />
526     <br />
527     NameVirtualHost 172.20.30.40<br />
528     <br />
529     &lt;VirtualHost 172.20.30.40 172.20.30.50&gt;<br />
530     <indent>
531         DocumentRoot /www/example2<br />
532         ServerName www.example.org<br />
533         # ...<br />
534     </indent>
535     &lt;/VirtualHost&gt;<br />
536     <br />
537     &lt;VirtualHost 172.20.30.40&gt;<br />
538     <indent>
539         DocumentRoot /www/example3<br />
540         ServerName www.example.net<br />
541         ServerAlias *.example.net<br />
542         # ...<br />
543     </indent>
544     &lt;/VirtualHost&gt;
545     </example>
546
547     <p>このバーチャルホストは新しいアドレス (IP ベースのバーチャルホストとして)
548     と古いアドレス(名前ベースのバーチャルホストとして) の両方から
549     アクセスできます。</p>
550
551     </section>
552
553     <section id="serverpath"><title><code>ServerPath</code> ディレクティブを
554     使う</title>
555
556     <p>名前ベースのバーチャルホストが二つあるサーバがあるとします。
557     正しいバーチャルホストを得るためにはクライアントは正しい
558     <code>Host:</code> ヘッダを送らなければなりません。
559     古い HTTP/1.0 はそのようなヘッダを送らないので、Apache はクライアントが
560     どのバーチャルホストを意図したのかさっぱりわかりません
561     (なので、主バーチャルホストでリクエストを扱います)。
562     可能な限りの下位互換性を得るため、名前ベースのバーチャルホストの
563     URL 接頭辞へのリンクの書かれたページを返す、
564     主バーチャルホストが作成されます。</p>
565
566     <example>
567     <title>サーバの設定</title>
568
569     NameVirtualHost 172.20.30.40<br />
570     <br />
571     &lt;VirtualHost 172.20.30.40&gt;<br />
572     <indent>
573         # primary vhost<br />
574         DocumentRoot /www/subdomain<br />
575         RewriteEngine On<br />
576         RewriteRule ^/.* /www/subdomain/index.html<br />
577         # ...<br />
578     </indent>
579     &lt;/VirtualHost&gt;<br />
580     <br />
581     &lt;VirtualHost 172.20.30.40&gt;<br />
582     DocumentRoot /www/subdomain/sub1<br />
583     <indent>
584         ServerName www.sub1.domain.tld<br />
585         ServerPath /sub1/<br />
586         RewriteEngine On<br />
587         RewriteRule ^(/sub1/.*) /www/subdomain$1<br />
588         # ...<br />
589     </indent>
590     &lt;/VirtualHost&gt;<br />
591     <br />
592     &lt;VirtualHost 172.20.30.40&gt;<br />
593     <indent>
594         DocumentRoot /www/subdomain/sub2<br />
595         ServerName www.sub2.domain.tld<br />
596         ServerPath /sub2/<br />
597         RewriteEngine On<br />
598         RewriteRule ^(/sub2/.*) /www/subdomain$1<br />
599         # ...<br />
600     </indent>
601     &lt;/VirtualHost&gt;
602     </example>
603
604     <p><directive module="core">ServerPath</directive> ディレクティブの設定に
605     より、URL <code>http://www.sub1.domain.tld/sub1/</code> は
606     <em>常に</em> sub1-vhost により扱われます。URL
607     <code>http://www.sub1.domain.tld/</code> へのリクエストは
608     クライアントが正しい <code>Host:</code> ヘッダを送ったときにのみ
609     sub1-vhost から送られます。<code>Host:</code> ヘッダがなければ
610     クライアントは主ホストの情報ページを得ます。</p>
611
612     <p>一つ奇妙な動作をする点があることは覚えておいてください。
613     <code>http://www.sub2.domain.tld/sub1/</code> へのリクエストも
614     <code>Host:</code> ヘッダがなければ sub1-vhost により扱われます。</p>
615
616     <p>正しい <code>Host:</code> ヘッダを送ったクライアントはどちらの
617     URL、<em>つまり</em>接頭辞がある方も無い方も使えるように
618     <directive module="mod_rewrite">RewriteRule</directive> ディレクティブが
619     使われています。</p>
620   </section>
621
622 </manualpage>