このドキュメントはmod_wsgiの翻訳です。
Apacheとmod_wsgiでMercurialのリポジトリを提供する
紹介
mod_wsgiはPythonのWSGIインターフェイス(わずかに修正されたhgwebdir.cgi)をサポートするPythonアプリケーションをホストできるシンプルなApacheモジュールです。これは(mod_pythonのように)"in server"プロセス、"daemon mode" (FastCGIと同等)として動作することができます。
むやみにドキュメントに従わないようにお願いします。少なくとも公式の mod_wsgi ドキュメンテーション (とても素晴らしいです)、とPublishingRepositoriesをお読み下さい。 Apache :-Dを適切に設定する方法を知っていることが求められます。
利点
- mod_pythonもしくはfastcgiのように、古い時代に築かれたCGIよりも遙かに速いです。
- mod_pythonよりもシンプルで、しかも速いです。
- FastCGIよりも設定が簡単です (例えば、Apache 2.2上でMercurialリポジトリを提供するためには suexec、mod_fcgid、flupと修正されたhgweb* スクリプトも必要になります)
不利な点
- mod_wsgiは比較的新しくテストされていません。
- あなた自身でコンパイルすることが必要になる場合があります(すなわちOS用のパッケージがない場合)。
前提条件
次のソフトウェアが必要です(テストしたバージョンは括弧内です。他のバージョンも動作するでしょう):
- Apache (2.2.6)
- mod_wsgi (1.1)
- Python (2.5.1)
- Mercurial (0.9.4)
- hgwebdir.wsgi
設定
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:
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、これらがなくても不自由をしません。
