<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Apache を使って Bazaar サーバーをたてる — Bazaar 2.6.0 documentation</title> <link rel="stylesheet" href="../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '2.6.0', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/translations.js"></script> <link rel="shortcut icon" href="../_static/bzr.ico"/> <link rel="top" title="Bazaar 2.6.0 documentation" href="../index.html" /> <link rel="up" title="Bazaarユーザーガイド" href="index.html" /> <link rel="next" title="プラグインを書く" href="writing_a_plugin.html" /> <link rel="prev" title="Eメールを設定する" href="setting_up_email.html" /> </head> <body> <div class="related"> <h3>ナビゲーション</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="writing_a_plugin.html" title="プラグインを書く" accesskey="N">次へ</a></li> <li class="right" > <a href="setting_up_email.html" title="Eメールを設定する" accesskey="P">前へ</a> |</li> <li><a href="../index.html">目次 (2.6.0)</a> »</li> <li><a href="index.html" accesskey="U">Bazaarユーザーガイド</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="apache-bazaar"> <h1>Apache を使って Bazaar サーバーをたてる<a class="headerlink" href="#apache-bazaar" title="このヘッドラインへのパーマリンク">¶</a></h1> <p>このドキュメントでは、 Apache 2.0 と FastCGI, mod_python, mod_wsgi の どれかを利用して Bazaar の HTTP スマートサーバーをセットアップする方法を 説明します。</p> <p>スマートサーバーに関する詳細な情報とそれを設定する他の方法に関しては、 <a class="reference external" href="server.html">スマートサーバーのドキュメント</a> を参照してください。</p> <div class="section" id="id2"> <h2>例<a class="headerlink" href="#id2" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>プレーンなHTTPで <cite>/srv/example.com/www/code</cite> を <cite>http://example.com/code/...</cite> として すでに公開しているとします。これはbzrのブランチと <cite>/srv/example.com/www/code/branch-one</cite> と <cite>/srv/example.com/www/code/my-repo/branch-two</cite> のようなディレクトリを含みます。 既存のHTTP形式のアクセス権限に加えてリードオンリーのスマートサーバーのアクセス権限を これらのディレクトリに提供したい場合を考えます。</p> </div> <div class="section" id="apache-2-0"> <h2>Apache 2.0を設定する<a class="headerlink" href="#apache-2-0" title="このヘッドラインへのパーマリンク">¶</a></h2> <div class="section" id="fastcgi"> <h3>FastCGI<a class="headerlink" href="#fastcgi" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>最初に、mod_fastcgiを設定します。たとえば次の行をhttpd.confに追加します:</p> <div class="highlight-python"><pre>LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so FastCgiIpcDir /var/lib/apache2/fastcgi</pre> </div> <p>我々の例では、<cite>http://example.com/code</cite> で <cite>/srv/example.com/www/code</cite> をすでに提供しているので 既存のApacheの設定は次のようになります:</p> <div class="highlight-python"><pre>Alias /code /srv/example.com/www/code <Directory /srv/example.com/www/code> Options Indexes # ... </Directory></pre> </div> <p>.bzr/smartの形式で終わるURLに対するすべてのリクエストを扱うために 次のように変更する必要があります:</p> <div class="highlight-python"><pre>Alias /code /srv/example.com/www/code <Directory /srv/example.com/www/code> Options Indexes FollowSymLinks RewriteEngine On RewriteBase /code RewriteRule ^(.*/)?\.bzr/smart$ /srv/example.com/scripts/bzr-smart.fcgi </Directory> # bzr-smart.fcgiはDocumentRootの元に存在しないので、実行されるように # AliasはこれをURLの名前空間のエイリアスにする。 Alias /srv/example.com/scripts/bzr-smart.fcgi /srv/example.com/scripts/bzr-smart.fcgi <Directory /srv/example.com/scripts> Options ExecCGI <Files bzr-smart.fcgi> SetHandler fastcgi-script </Files> </Directory></pre> </div> <p>この設定はFastCGIを通して <cite>/code</cite> 内部の <cite>/.bzr/smart</cite> で終わるURLに対する Bazaarのスマートサーバーへのリクエストを扱うようにApacheに指示します。</p> <p>詳細な情報は <a class="reference external" href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html">mod_rewrite</a> と <a class="reference external" href="http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html">mod_fastcgi</a> のドキュメントを参照してください。</p> </div> <div class="section" id="mod-python"> <h3>mod_python<a class="headerlink" href="#mod-python" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>最初に、次のようなコードを httpd.conf に追加して mod_python を設定します:</p> <div class="highlight-python"><pre>LoadModule python_module /usr/lib/apache2/modules/mod_python.so</pre> </div> <p>FastCGI と同じ方法で mod_rewrite を用いて書き換えルールを定義します:</p> <div class="highlight-python"><pre>RewriteRule ^(.*/)?\.bzr/smart$ /srv/example.com/scripts/bzr-smart.fcgi</pre> </div> <p>変更は次のようになります:</p> <div class="highlight-python"><pre>RewriteRule ^(.*/)?\.bzr/smart$ /srv/example.com/scripts/bzr-smart.py</pre> </div> <p>mod_fastcgi のように、スクリプトがどのように扱われるのかも定義します:</p> <div class="highlight-python"><pre>Alias /srv/example.com/scripts/bzr-smart.py /srv/example.com/scripts/bzr-smart.py <Directory /srv/example.com/scripts> <Files bzr-smart.py> PythonPath "sys.path+['/srv/example.com/scripts']" AddHandler python-program .py PythonHandler bzr-smart::handler </Files> </Directory></pre> </div> <p>この設定は mod_python を通して <cite>/code</cite> 内部の <cite>/.bzr/smart</cite> で終わるURLに対するリクエストを Bazaar のスマートサーバーに渡すように指示します。</p> <p>注: bzrlib が PATH の中に存在しない場合、次の行を変更する必要があります:</p> <div class="highlight-python"><pre>PythonPath "sys.path+['/srv/example.com/scripts']"</pre> </div> <p>変更後は次のようになります:</p> <div class="highlight-python"><pre>PythonPath "['/path/to/bzr']+sys.path+['/srv/example.com/scripts']"</pre> </div> <p>詳細な情報は <a class="reference external" href="http://www.modpython.org/">mod_python</a> のドキュメントを参照してください。</p> </div> <div class="section" id="mod-wsgi"> <h3>mod_wsgi<a class="headerlink" href="#mod-wsgi" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>最初に、 a2enmod wsgi などで mod_wsgi を有効にしておきます。 次に、 <cite>.bzr/smart</cite> で終わる全ての URL に対するリクエストを mod_wsgi 経由 で処理するように設定します。設定例は次のようになります。</p> <div class="highlight-python"><pre>WSGIScriptAliasMatch ^/code/.*/\.bzr/smart$ /srv/example.com/scripts/bzr.wsgi #The three next lines allow regular GETs to work too RewriteEngine On RewriteCond %{REQUEST_URI} !^/code/.*/\.bzr/smart$ RewriteRule ^/code/(.*/\.bzr/.*)$ /srv/example.com/www/code/$1 [L] <Directory /srv/example.com/www/code> WSGIApplicationGroup %{GLOBAL} </Directory></pre> </div> <p>この設定では、 Apache は <cite>/code</cite> 以下の <cite>/.bzr/smart</cite> で終わる URL に 対する全てのリクエストを WSGI 経由で Bazaar のスマートサーバーに渡し、 それ以外の全てのリクエストは Apache が直接扱うようにしています。</p> <p>詳細は <a class="reference external" href="http://code.google.com/p/modwsgi/">mod_wsgi</a> のドキュメントを参照してください。</p> </div> </div> <div class="section" id="bazaar"> <h2>Bazaarを設定する<a class="headerlink" href="#bazaar" title="このヘッドラインへのパーマリンク">¶</a></h2> <div class="section" id="id5"> <h3>FastCGI<a class="headerlink" href="#id5" title="このヘッドラインへのパーマリンク">¶</a></h3> <p><cite>/srv/example.com/scripts/bzr-smart.fcgi</cite> でスマートサーバーを実行するためにApacheを設定しました。 これはスマートサーバーを設定するために書く必要のある単なるシンプルなスクリプトで サーバーをFastCGIのゲートウェイに結びつけます。次のようになります:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">fcgi</span> <span class="kn">from</span> <span class="nn">bzrlib.transport.http</span> <span class="kn">import</span> <span class="n">wsgi</span> <span class="n">smart_server_app</span> <span class="o">=</span> <span class="n">wsgi</span><span class="o">.</span><span class="n">make_app</span><span class="p">(</span> <span class="n">root</span><span class="o">=</span><span class="s">'/srv/example.com/www/code'</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s">'/code/'</span><span class="p">,</span> <span class="n">path_var</span><span class="o">=</span><span class="s">'REQUEST_URI'</span><span class="p">,</span> <span class="n">readonly</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">load_plugins</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">enable_logging</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> <span class="n">fcgi</span><span class="o">.</span><span class="n">WSGIServer</span><span class="p">(</span><span class="n">smart_server_app</span><span class="p">)</span><span class="o">.</span><span class="n">run</span><span class="p">()</span> </pre></div> </div> <p> <cite>fcgi</cite> のモジュールはhttp://svn.saddi.com/py-lib/trunk/fcgi.pyで見つかります。 これは <a class="reference external" href="http://www.saddi.com/software/flup/">flup</a> の一部です。</p> </div> <div class="section" id="id6"> <h3>mod_python<a class="headerlink" href="#id6" title="このヘッドラインへのパーマリンク">¶</a></h3> <p><cite>/srv/example.com/scripts/bzr-smart.py</cite> でスマートサーバーを実行するためにApacheを設定しました。 これはスマートサーバーを設定するために書く必要のあるシンプルなスクリプトでサーバーをmod_pythonの ゲートウェイに結びつけます。次のようになります:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">modpywsgi</span> <span class="kn">from</span> <span class="nn">bzrlib.transport.http</span> <span class="kn">import</span> <span class="n">wsgi</span> <span class="n">smart_server_app</span> <span class="o">=</span> <span class="n">wsgi</span><span class="o">.</span><span class="n">make_app</span><span class="p">(</span> <span class="n">root</span><span class="o">=</span><span class="s">'/srv/example.com/www/code'</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s">'/code/'</span><span class="p">,</span> <span class="n">path_var</span><span class="o">=</span><span class="s">'REQUEST_URI'</span><span class="p">,</span> <span class="n">readonly</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">load_plugins</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">enable_logging</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> <span class="k">def</span> <span class="nf">handler</span><span class="p">(</span><span class="n">request</span><span class="p">):</span> <span class="sd">"""Handle a single request."""</span> <span class="n">wsgi_server</span> <span class="o">=</span> <span class="n">modpywsgi</span><span class="o">.</span><span class="n">WSGIServer</span><span class="p">(</span><span class="n">smart_server_app</span><span class="p">)</span> <span class="k">return</span> <span class="n">wsgi_server</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">request</span><span class="p">)</span> </pre></div> </div> <p><cite>modpywsgi</cite> モジュールは <a class="reference external" href="http://ice.usq.edu.au/svn/ice/trunk/apps/ice-server/modpywsgi.py">http://ice.usq.edu.au/svn/ice/trunk/apps/ice-server/modpywsgi.py</a> で見つかります。 これは <a class="reference external" href="http://dev.pocoo.org/projects/pocoo/">pocoo</a> の一部でした。 modpywsgi.py を bzr-smart.py と同じディレクトリ (すなわち/srv/example.com/scripts/)に設置していることを確認してください。</p> </div> <div class="section" id="id7"> <h3>mod_wsgi<a class="headerlink" href="#id7" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>We’ve configured Apache to run the smart server at <cite>/srv/example.com/scripts/bzr.wsgi</cite>. This is just a simple script we need to write to configure a smart server, and glue it to the WSGI gateway. Here’s what it looks like:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">bzrlib.transport.http</span> <span class="kn">import</span> <span class="n">wsgi</span> <span class="k">def</span> <span class="nf">application</span><span class="p">(</span><span class="n">environ</span><span class="p">,</span> <span class="n">start_response</span><span class="p">):</span> <span class="n">app</span> <span class="o">=</span> <span class="n">wsgi</span><span class="o">.</span><span class="n">make_app</span><span class="p">(</span> <span class="n">root</span><span class="o">=</span><span class="s">"/srv/example.com/www/code/"</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s">"/code"</span><span class="p">,</span> <span class="n">readonly</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">enable_logging</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span> <span class="k">return</span> <span class="n">app</span><span class="p">(</span><span class="n">environ</span><span class="p">,</span> <span class="n">start_response</span><span class="p">)</span> </pre></div> </div> </div> </div> <div class="section" id="id8"> <h2>クライアント<a class="headerlink" href="#id8" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>これで <cite>bzr+http://</cite> 形式のURLやただの <cite>http://</cite> のURLを利用できます:</p> <div class="highlight-python"><pre>bzr log bzr+http://example.com/code/my-branch</pre> </div> <p>プレーンなHTTP形式のアクセスも持続します:</p> <div class="highlight-python"><pre>bzr log http://example.com/code/my-branch</pre> </div> </div> <div class="section" id="id9"> <h2>高度な設定<a class="headerlink" href="#id9" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>BazaarのHTTPスマートサーバーはWSGIアプリケーションなので、 WSGI標準に準拠するサードパーティのWSGIのミドルウェアもしくはサーバーで利用できます。 唯一の要件は以下のとおりです:</p> <blockquote> <div><ul class="simple"> <li><cite>SmartWSGIApp</cite> をコンストラクトするためには、それが提供する <strong>root transport</strong> を指定する必要があります。</li> <li>それぞれのリクエストの <cite>environ</cite> dict は <strong>‘bzrlib.relpath’</strong> 変数の設定を持たなければなりません。</li> </ul> </div></blockquote> <p>この例で使われている <cite>make_app</cite> ヘルパーは それに渡される <cite>root</cite> パスに基づいたトランスポートを伴う <cite>SmartWSGIApp</cite> をコンストラクトし、引数 <cite>prefix</cite> と`path_var` に基づくそれぞれのリクエストに対する <cite>bzrlib.relpath</cite> を算出します。 上記の例において、これは (Apacheによって設定される)’REQUEST_URI’ を取り、接頭辞の ‘/code/’ と接尾辞の ‘/.bzr/smart’ をはぎ取り、それを ‘bzrlib.relpath’ として設定するので、 ‘/code/foo/bar/.bzr/smart’ に対するリクエストは ‘foo/bzr’ の ‘bzrlib.relpath’ になります。</p> <p><cite>SmartWSGIApp</cite> を直接コンストラクトすることで、ローカルではないトランスポートに対して スマートサーバーを設定するもしくは任意任意のパスの変換を行うことは可能です。 詳細な情報に関しては <cite>bzrlib.transport.http.wsgi</cite> のdocstringsと <a class="reference external" href="http://www.python.org/dev/peps/pep-0333/">WSGI標準</a> を参照してください。</p> <div class="section" id="http-push"> <h3>HTTP スマートサーバー経由で push する<a class="headerlink" href="#http-push" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>HTTP スマートサーバーを通してデータをプッシュすることは可能です。 これを行うための最も簡単な方法は、 <tt class="docutils literal"><span class="pre">wsgi.make_app()</span></tt> コールに <tt class="docutils literal"><span class="pre">readonly=False</span></tt> を 提供するだけです。ただし、スマートプロトコルは認証機能が含まれないので注意してください。 書き込みのサポートを有効にする場合、 実際にシステム上のデータを書き込みできる人を制限するために、 <tt class="docutils literal"><span class="pre">.bzr/smart</span></tt> URLへの権限を制限するとよいでしょう。例えば Apache で次のような設定を します。</p> <div class="highlight-python"><pre><Location /code> AuthType Basic AuthName "example" AuthUserFile /srv/example.com/conf/auth.passwd <LimitExcept GET> Require valid-user </LimitExcept> </Location></pre> </div> <p>現時点では、同じURLに対して読み込み限定の人と読み込みと書き込みの人を 分けることはできません。 (認証を行う)HTTPレイヤーにおいて、すべては単なるPOSTリクエストだからです。 しかしながら、HTTPSアクセスの場合に認証が必要な書き込みサーバーを使い、 プレーンなHTTPは読み込み限定のアクセスを許可することはできます。</p> <p>HTTPS サイトに対してアクセスしたときに bzr が次のようなエラーを表示する 場合:</p> <div class="highlight-python"><pre>bzr: ERROR: Connection error: curl connection error (server certificate verification failed. CAfile:/etc/ssl/certs/ca-certificates.crt CRLfile: none)</pre> </div> <p>You can workaround it by using <tt class="docutils literal"><span class="pre">https+urllib</span></tt> rather than <tt class="docutils literal"><span class="pre">http</span></tt> in your URL, or by uninstalling pycurl. See <a class="reference external" href="https://bugs.launchpad.net/bzr/+bug/82086">bug 82086</a> for more details.</p> <p>URL に <tt class="docutils literal"><span class="pre">https</span></tt> の代わりに <tt class="docutils literal"><span class="pre">https+urllib</span></tt> を使うことで問題を回避 できます。 詳細については <a class="reference external" href="https://bugs.launchpad.net/bzr/+bug/82086">bug 82086</a> を参照してください。</p> </div> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="../index.html">目次</a></h3> <ul> <li><a class="reference internal" href="#">Apache を使って Bazaar サーバーをたてる</a><ul> <li><a class="reference internal" href="#id2">例</a></li> <li><a class="reference internal" href="#apache-2-0">Apache 2.0を設定する</a><ul> <li><a class="reference internal" href="#fastcgi">FastCGI</a></li> <li><a class="reference internal" href="#mod-python">mod_python</a></li> <li><a class="reference internal" href="#mod-wsgi">mod_wsgi</a></li> </ul> </li> <li><a class="reference internal" href="#bazaar">Bazaarを設定する</a><ul> <li><a class="reference internal" href="#id5">FastCGI</a></li> <li><a class="reference internal" href="#id6">mod_python</a></li> <li><a class="reference internal" href="#id7">mod_wsgi</a></li> </ul> </li> <li><a class="reference internal" href="#id8">クライアント</a></li> <li><a class="reference internal" href="#id9">高度な設定</a><ul> <li><a class="reference internal" href="#http-push">HTTP スマートサーバー経由で push する</a></li> </ul> </li> </ul> </li> </ul> <h4>前のトピックへ</h4> <p class="topless"><a href="setting_up_email.html" title="前の章へ">Eメールを設定する</a></p> <h4>次のトピックへ</h4> <p class="topless"><a href="writing_a_plugin.html" title="次の章へ">プラグインを書く</a></p> <h3>このページ</h3> <ul class="this-page-menu"> <li><a href="../_sources/user-guide/http_smart_server.txt" rel="nofollow">ソースコードを表示</a></li> </ul> <div id="searchbox" style="display: none"> <h3>クイック検索</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="検索" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> モジュール、クラス、または関数名を入力してください </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>ナビゲーション</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="writing_a_plugin.html" title="プラグインを書く" >次へ</a></li> <li class="right" > <a href="setting_up_email.html" title="Eメールを設定する" >前へ</a> |</li> <li><a href="../index.html">目次 (2.6.0)</a> »</li> <li><a href="index.html" >Bazaarユーザーガイド</a> »</li> </ul> </div> <div class="footer"> © Copyright 2009-2011 Canonical Ltd. このドキュメントは <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3 で生成しました。 </div> </body> </html>