このドキュメントは["mod_wsgi"]の翻訳です。

Apacheとmod_wsgiでMercurialのリポジトリを提供する

TableOfContents

紹介

[http://code.google.com/p/modwsgi/ mod_wsgi]はPythonのWSGIインターフェイス(わずかに修正されたhgwebdir.cgi)をサポートするPythonアプリケーションをホストできるシンプルなApacheモジュールです。これは(mod_pythonのように)"in server"プロセス、"daemon mode" (FastCGIと同等)として動作することができます。

むやみにドキュメントに従わないようにお願いします。少なくとも公式の [http://code.google.com/p/modwsgi/w/list mod_wsgi ドキュメンテーション] (とても素晴らしいです)、とPublishingRepositoriesをお読み下さい。 Apache :-Dを適切に設定する方法を知っていることが求められます。

利点

不利な点

前提条件

次のソフトウェアが必要です(テストしたバージョンは括弧内です。他のバージョンも動作するでしょう):

設定

mod_wsgi

あなたのオペレーティングシステム用のmod_wsgiパッケージが見つからない場合、あなた自身でコンパイルしなければなりません。

例です

$ tar xvf mod_wsgi-1.1.tar.gz
$ cd mod_wsgi-1.1
$ ./configure
$ make
$ su -c "make install"

wsgiモジュールをロードするためにhttpd.confファイルを編集して下さい:

LoadModule wsgi_module libexec/httpd/mod_wsgi.so

Apache

このサンプルのセットアップにおいて、個別のバーチャルホスト(hg.example.net)からMercurialリポジトリを提供しています。リポジトリはhtdocsディレクトリにあり、修正されたhgwebdir.cgiスクリプト(hgwebdir.wsgi)によって提供されます。

<VirtualHost *:80>
    ServerName hg.example.net
    DocumentRoot /var/www/vhosts/hg.example.net/htdocs
    ErrorLog /var/log/httpd/hg.example.net-error_log
    CustomLog /var/log/httpd/hg.example.net-access_log common

    WSGIScriptAliasMatch ^(.*) /var/www/vhosts/hg.example.net/cgi-bin/hgwebdir.wsgi$1

    # To enable "daemon" mode, uncomment following lines. (Read mod_wsgi docs for more info)
    # WSGIDaemonProcess hg.example.net user=USER group=GROUP threads=15 maximum-requests=1000
    # WSGIProcessGroup hg.example.net

    <Directory /var/www/vhosts/hg.example.net/htdocs>
        Options FollowSymlinks
        DirectoryIndex index.html

        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>

    <Directory /var/www/vhosts/hg.example.net/cgi-bin>
        Options ExecCGI FollowSymlinks
        AddHandler cgi-script .cgi

        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Mercurial

Merucialに付属しているhgwebdir.cgiの最後の行だけを変更する必要があります。 下記のコードはショートバージョン -hgwebdir.wsgi:

   1 #!/usr/bin/env python
   2 
   3 from mercurial.hgweb.hgwebdir_mod import hgwebdir
   4 from mercurial.hgweb.request import wsgiapplication
   5 
   6 def make_web_app():
   7     return hgwebdir("hgwebdir.config")
   8 
   9 application = wsgiapplication(make_web_app)

hgwebdir.configファイルは次のようになります:

[web]
style = gitweb

[collections]
/var/www/vhosts/hg.example.net/htdocs = /var/www/vhosts/hg.example.net/htdocs

筆者はmod_wsgiはApache上のpythonアプリケーションの未来であると思います。 本当に素晴らしく、初期の段階でありますが、より素晴らしいものになることを期待しています。

さよならmod_python/fastcgi、これらがなくても不自由をしません。


CategoryJapanese