name-based.html.ja.utf8 23 KB
Newer Older
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja"><head><!--
        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
              This file is generated from xml source: DO NOT EDIT
        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
      -->
<title>名前ベースのバーチャルホスト - Apache HTTP サーバ バージョン 2.2</title>
<link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
<link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
<link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="../style/css/prettify.css" />
<script src="../style/scripts/prettify.min.js" type="text/javascript">
</script>

<link href="../images/favicon.ico" rel="shortcut icon" /></head>
<body id="manual-page"><div id="page-header">
<p class="menu"><a href="../mod/">モジュール</a> | <a href="../mod/directives.html">ディレクティブ</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">用語</a> | <a href="../sitemap.html">サイトマップ</a></p>
<p class="apache">Apache HTTP サーバ バージョン 2.2</p>
<img alt="" src="../images/feather.gif" /></div>
<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div>
<div id="path">
<a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP サーバ</a> &gt; <a href="http://httpd.apache.org/docs/">ドキュメンテーション</a> &gt; <a href="../">バージョン 2.2</a> &gt; <a href="./">バーチャルホスト</a></div><div id="page-content"><div id="preamble"><h1>名前ベースのバーチャルホスト</h1>
<div class="toplang">
<p><span>翻訳済み言語: </span><a href="../de/vhosts/name-based.html" hreflang="de" rel="alternate" title="Deutsch">&nbsp;de&nbsp;</a> |
<a href="../en/vhosts/name-based.html" hreflang="en" rel="alternate" title="English">&nbsp;en&nbsp;</a> |
<a href="../fr/vhosts/name-based.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a> |
<a href="../ja/vhosts/name-based.html" title="Japanese">&nbsp;ja&nbsp;</a> |
<a href="../ko/vhosts/name-based.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
<a href="../tr/vhosts/name-based.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
</div>
<div class="outofdate">この日本語訳はすでに古くなっている
            可能性があります。
            最近更新された内容を見るには英語版をご覧下さい。
        </div>

    <p>この文書では名前ベースのバーチャルホストをどんなとき、
    どうやって使うかを説明します。</p>
</div>
<div id="quickview"><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#namevip">名前ベースと IP ベースのバーチャルホストの比較</a></li>
<li><img alt="" src="../images/down.gif" /> <a href="#using">名前ベースのバーチャルホストを利用する</a></li>
<li><img alt="" src="../images/down.gif" /> <a href="#compat">古いブラウザとの互換性</a></li>
</ul><h3>参照</h3><ul class="seealso"><li><a href="ip-based.html">ネームベースのバーチャルホスト</a></li><li><a href="details.html">バーチャルホストのマッチングについての詳細</a></li><li><a href="mass.html">大量のバーチャルホストの動的な設定</a></li><li><a href="examples.html">バーチャルホストの一般的な設定例</a></li><li><a href="examples.html#serverpath">ServerPath 設定例</a></li></ul><ul class="seealso"><li><a href="#comments_section">コメント</a></li></ul></div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="namevip" id="namevip">名前ベースと IP ベースのバーチャルホストの比較</a></h2>

    <p>IP ベースのバーチャルホストでは、応答する
    バーチャルホストへのコネクションを決定するために IP
    アドレスを使用します。ですから、それぞれのホストに個々に IP
    アドレスが必要になります。これに対して名前ベースのバーチャルホストでは、
    クライアントが HTTP ヘッダの一部としてホスト名を告げる、
    ということに依存します。この技術で同一 IP 
    アドレスを異なる多数のホストで共有しています。</p>

    <p>名前ベースのバーチャルホストは通常単純で、それぞれのホスト名と
    それに対応する正確な IP アドレスを DNS で設定し、異なる
    ホスト名を区別するように Apache HTTP サーバを設定するだけです。
    さらに、名前ベースのバーチャルホストは不足する IP
    アドレスの需要を緩和します。したがって、IP ベースのバーチャルホストを
    選択すべき特定の理由がなければ名前ベースのバーチャルホストを使うべきです。
    IP ベースのバーチャルホストを使用することを考慮する理由として、</p>

    <ul> 
      <li>名前ベースのバーチャルホストに対応していない古いクライアントがある
      名前ベースのバーチャルホストが働くためには、クライアントは
      HTTP ホストヘッダを送ってこなければなりません。
      これは HTTP/1.1 の仕様で要求されていて、すべての現代的な
      HTTP/1.0 ブラウザでも拡張として実装されています。
      とても古いクライアントをサポートしつつ、名前ベースの
      バーチャルホストを行いたい場合は、この文書の最後の方に
      書かれている解決策になるかもしれない方法を見てください。</li>

      <li>名前ベースのバーチャルホストは SSL プロトコルの特徴により、
      SSL セキュアサーバには使えません。</li>

      <li>オペレーティングシステムやネットワーク装置のなかには、
      別の IP アドレス上でない場合、複数のホストを別扱いできないような
      帯域管理の方法を実装しているものがあります。</li>
    </ul>

</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="using" id="using">名前ベースのバーチャルホストを利用する</a></h2>

<table class="related"><tr><th>関連モジュール</th><th>関連ディレクティブ</th></tr><tr><td><ul><li><code class="module"><a href="../mod/core.html">core</a></code></li></ul></td><td><ul><li><code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code></li><li><code class="directive"><a href="../mod/core.html#namevirtualhost">NameVirtualHost</a></code></li><li><code class="directive"><a href="../mod/core.html#serveralias">ServerAlias</a></code></li><li><code class="directive"><a href="../mod/core.html#servername">ServerName</a></code></li><li><code class="directive"><a href="../mod/core.html#serverpath">ServerPath</a></code></li><li><code class="directive"><a href="../mod/core.html#virtualhost">VirtualHost</a></code></li><li><code class="directive"><a href="../mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code></li></ul></td></tr></table>

    <p>名前ベースのバーチャルホストを使うには、そのホストへの
    リクエストを受け付けるサーバの IP アドレス (もしかしたらポートも)
    を指定する必要があります。
    これは <code class="directive"><a href="../mod/core.html#namevirtualhost">NameVirtualHost</a></code>
    ディレクティブで設定します。通常、<code class="directive"><a href="../mod/core.html#namevirtualhost">NameVirtualHost</a></code>
    <code>*</code> の属性を使ってサーバの全ての IP アドレスを使います。
    (例えば SSL の使用などで) 複数のポートを使うことを計画しているのであれば、
    引数に <code>*:80</code> のようにポートも含めるようにしてください。
    <code class="directive"><a href="../mod/core.html#namevirtualhost">NameVirtualHost</a></code> ディレクティブで
    IP アドレスを書いても、
    自動的にサーバがその IP アドレスをリッスンするということはないことに
    注意してください。詳細は「<a href="../bind.html">Apache の使うアドレスと
    ポートを設定する</a>」を読んでください。さらに、ここで指定された
    IP アドレスは全てサーバのネットワークインターフェースと関連付けられて
    いなければなりません。</p>

    <p>次は、扱うホストそれぞれに対して <code class="directive"><a href="../mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code> ブロックを
    作成してください。<code class="directive"><a href="../mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code>
    ディレクティブの引数は <code class="directive"><a href="../mod/core.html#namevirtualhost">NameVirtualHost</a></code>
    ディレクティブの引数と同じにしてください (すなわち、IP アドレスか、全てのアドレスを意味する
    <code>*</code>)。それぞれの <code class="directive"><a href="../mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code>
    ディレクティブの中には、最低限、どのホストが扱われるかを示す <code class="directive"><a href="../mod/core.html#servername">ServerName</a></code> ディレクティブと、
    そのホスト用のコンテンツがファイルシステム上のどこにあるかを示す
    <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> ディレクティブを
    書く必要があります。</p>

    <div class="note"><h3>メインホストはなくなります</h3>
        <p>既にあるウェブサーバにバーチャルホストを追加する場合、
        既存のウェブサーバに対しても <code class="directive"><a href="../mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code>
        ブロックを作らなければなりません。このバーチャルホストの
        <code class="directive"><a href="../mod/core.html#servername">ServerName</a></code>
        <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code>
        は、グローバルな <code class="directive"><a href="../mod/core.html#servername">ServerName</a></code>
        <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code>
        と同じものにします。また、このバーチャルホストを設定ファイルの中で
        先頭に置いて、デフォルトホストとして動作するようにします。</p>
    </div>

    <p>たとえば、<code>www.domain.tld</code> を動かしていて、
    さらにバーチャルホスト <code>www.otherdomain.tld</code>
    を追加するとしましょう。このバーチャルホストは同一 IP を指しているとします。
    そのような場合は、<code>httpd.conf</code>
    に以下のようなコードを追加するだけです</p>

    <div class="example"><p><code>
        NameVirtualHost *:80<br />
        <br />
        &lt;VirtualHost *:80&gt;<br />
        <span class="indent">
            ServerName www.domain.tld<br />
            ServerAlias domain.tld *.domain.tld<br />
            DocumentRoot /www/domain<br />
        </span>
        &lt;/VirtualHost&gt;<br />
        <br />
        &lt;VirtualHost *:80&gt;<br />
        <span class="indent">ServerName www.otherdomain.tld<br />
            DocumentRoot /www/otherdomain<br />
        </span>
        &lt;/VirtualHost&gt;<br />
    </code></p></div>

    <p><code class="directive"><a href="../mod/core.html#namevirtualhost">NameVirtualHost</a></code> 及び
    <code class="directive"><a href="../mod/core.html#virtualhost">VirtualHost</a></code> のどちらの場合も、
    * の部分には明示的に IP アドレスを指定することができます。
    例えば、ある IP アドレスでは名前ベースのバーチャルホストを使いたい一方で、
    別の IP アドレスでは、他の IP ベースのバーチャルホストや
    別組の名前ベースのバーチャルホストを使いたい場合、
    そう設定することになるでしょう。</p>

    <p>複数の名前でサーバアクセスができるようにしたいことも多いでしょう。
    このようなことは、<code class="directive"><a href="../mod/core.html#serveralias">ServerAlias</a></code> ディレクティブを <code class="directive"><a href="../mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code>
    セクションに記述することで実現できます。
    例えば上記の <code class="directive"><a href="../mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code> の例であれば、
    次のように一覧に挙げられた名前が、
    ユーザが同一のウェブサイトとして目にして使用できるサーバ名である、
<code class="directive"><a href="../mod/core.html#serveralias">ServerAlias</a></code>
    ディレクティブで指定できます。</p> 

    <div class="example"><p><code>
        ServerAlias domain.tld *.domain.tld
    </code></p></div>

    <p><code>domain.tld</code> ドメインへの全てのホストへのリクエストは
    <code>www.domain.tld</code> のバーチャルホストが処理します。
    名前をマッチさせるために、ワイルドカード文字 * や ? 
    を使用することもできます。もちろん思いつきの名前を作って、
    <code class="directive"><a href="../mod/core.html#servername">ServerName</a></code>
    <code class="directive"><a href="../mod/core.html#serveralias">ServerAlias</a></code>
    にその名前を書くといったことはできません。まずは、
    これらの名前が サーバに付けられた IP アドレスにマップされるように
    DNS サーバを適切に設定しなければなりません。</p>

    <p>最後に、<code class="directive"><a href="../mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code> コンテナの中に
    他のディレクティブを書くことで、バーチャルホストの設定を細かく調整
    することができます。
    ほとんどのディレクティブはこれらのコンテナに設置することができて、
    変更点はそのバーチャルホストに対してのみ有効になります。
    どのディレクティブを書くことができるかは、ディレクティブの <a href="../mod/directive-dist.html#context">コンテキスト</a>
    調べてください。<em>主サーバコンテキスト</em>
    (<code class="directive"><a href="../mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code>
    コンテナの外) の設定用ディレクティブはバーチャルホストでの設定で
    上書きされない場合のみ使用されます。</p>

    <p>リクエストが来ると、サーバはまず最初に <code class="directive"><a href="../mod/core.html#namevirtualhost">&lt;NameVirtualHost&gt;</a></code>
    にマッチする IP アドレスかどうかをチェックします。マッチすれば
    マッチした IP アドレスの <code class="directive"><a href="../mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code>
    のそれぞれのセクションの中から 
    <code class="directive"><a href="../mod/core.html#servername">ServerName</a></code>
    <code class="directive"><a href="../mod/core.html#serveralias">ServerAlias</a></code> 
    に要求されたホスト名があるか探します。
    見つかればそのサーバ用の設定を使います。マッチするバーチャルホスト
    が見つからなければ、マッチした IP アドレスの 
    <strong>リストの最初にあるバーチャルホスト</strong> が使われます。</p>

    <p>結果として、リストの最初のバーチャルホストが <em>デフォルト</em>
    バーチャルホストになります。IP アドレスが <code class="directive"><a href="../mod/core.html#namevirtualhost">NameVirtualHost</a></code>
    ディレクティブにマッチした場合は、<em>メインのサーバ</em>
    <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> 
<strong>決して使われません</strong>
    どのバーチャルホストにもマッチしないリクエストに対して、
    特別な設定をしたいのであれば、設定ファイル中の最初の
    <code>&lt;VirtualHost&gt;</code> コンテナにそれを記述してください。</p>

</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="compat" id="compat">古いブラウザとの互換性</a></h2>

    <p>以前述べたように、名前ベースのバーチャルホストが正しく動作する
    ために必要な情報を送ってこないクライアントが依然として存在しています。
    そのようなクライアントに対しては、該当する IP アドレスについて、
    一番最初に設定されているバーチャルホスト
    (<cite>プライマリ</cite>の名前ベースのバーチャルホスト)
    からページが送り返されます。</p>

    <div class="note"><h3>どのぐらい古いの ?</h3>
    <p>「古い」と表現している場合、本当に古いことを意味して使っています。
    不幸にして今現在でもこのような古いブラウザに遭遇することがあります。
    現在のブラウザは全て、名前ベースのバーチャルホストに必要な
    <code>Host</code> ヘッダを送ります。</p>
    </div>

    <p><a href="../mod/core.html#serverpath"><code>ServerPath</code></a>
    ディレクティブで対処が可能です。ちょっと不格好ですけれども。</p>

    <p>設定例</p>

    <div class="example"><p><code>
        NameVirtualHost 111.22.33.44<br />
        <br />
        &lt;VirtualHost 111.22.33.44&gt;<br />
        <span class="indent">
            ServerName www.domain.tld<br />
            ServerPath /domain<br />
            DocumentRoot /web/domain<br />
        </span>
        &lt;/VirtualHost&gt;<br />
    </code></p></div>

    <p>この例にはどういう意味があるでしょうか? これは
    "<code>/domain</code>" で始まる URI へのリクエストはすべて、
    バーチャルホスト <code>www.domain.tld</code> で処理される、
    という意味です。つまり、すべてのクライアントで
    <code>http://www.domain.tld/domain/</code> でアクセスできるページが、
    <code>Host:</code> ヘッダを送ってくるクライアントであれば
    <code>http://www.domain.tld/</code> としてもアクセスできる、
    という意味です。</p>

    <p>これが動作するようにするには、
    プライマリのバーチャルホストのページに
    <code>http://www.domain.tld/domain/</code> へのリンクを設置します。
    そして、バーチャルホストのページでは、純粋な相対リンク (<em>例:</em>
    "<code>file.html</code>" や "<code>../icons/image.gif</code>")、
    あるいは <code>/domain/</code> で始まるリンク (<em>例:</em>
    "<code>http://www.domain.tld/domain/misc/file.html</code>" や
    "<code>/domain/misc/file.html</code>") だけを設置します。</p>

    <p>これには、幾分かの規律が必要となりますが、
    このようなガイドラインを忠実に守ることにより、たいていの場合、
    すべてのブラウザで ― 新しいブラウザでも古いものでも ―
    作成したページが見えるということを保証します。</p>

</div></div>
<div class="bottomlang">
<p><span>翻訳済み言語: </span><a href="../de/vhosts/name-based.html" hreflang="de" rel="alternate" title="Deutsch">&nbsp;de&nbsp;</a> |
<a href="../en/vhosts/name-based.html" hreflang="en" rel="alternate" title="English">&nbsp;en&nbsp;</a> |
<a href="../fr/vhosts/name-based.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a> |
<a href="../ja/vhosts/name-based.html" title="Japanese">&nbsp;ja&nbsp;</a> |
<a href="../ko/vhosts/name-based.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
<a href="../tr/vhosts/name-based.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
</div><div class="top"><a href="#page-header"><img src="../images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">コメント</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&amp;A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
<script type="text/javascript"><!--//--><![CDATA[//><!--
var comments_shortname = 'httpd';
var comments_identifier = 'http://httpd.apache.org/docs/2.2/vhosts/name-based.html';
(function(w, d) {
    if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
        d.write('<div id="comments_thread"><\/div>');
        var s = d.createElement('script');
        s.type = 'text/javascript';
        s.async = true;
        s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
        (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
    }
    else { 
        d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
    }
})(window, document);
//--><!]]></script></div><div id="footer">
<p class="apache">Copyright 2014 The Apache Software Foundation.<br />この文書は <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a> のライセンスで提供されています。.</p>
<p class="menu"><a href="../mod/">モジュール</a> | <a href="../mod/directives.html">ディレクティブ</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">用語</a> | <a href="../sitemap.html">サイトマップ</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
if (typeof(prettyPrint) !== 'undefined') {
    prettyPrint();
}
//--><!]]></script>
</body></html>