TS-639にmod_wsgiをインストールする。

mod_wsgiのインストール

# ipkg install mod-wsgi
Installing mod-wsgi (3.2-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/ts509/cross/unstable/mod-wsgi_3.2-1_i686.ipk
Installing apache (2.2.15-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/ts509/cross/unstable/apache_2.2.15-1_i686.ipk
Installing e2fsprogs (1.41.9-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/ts509/cross/unstable/e2fsprogs_1.41.9-1_i686.ipk
Installing python25 (2.5.5-2) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/ts509/cross/unstable/python25_2.5.5-2_i686.ipk
Installing bzip2 (1.0.5-2) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/ts509/cross/unstable/bzip2_1.0.5-2_i686.ipk
Installing libstdc++ (6.0.9-6) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/ts509/cross/unstable/libstdc++_6.0.9-6_i686.ipk
Installing ncursesw (5.7-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/ts509/cross/unstable/ncursesw_5.7-1_i686.ipk
Configuring apache
update-alternatives: Linking //opt/sbin/htpasswd to /opt/sbin/apache-htpasswd
update-alternatives: Linking //opt/sbin/httpd to /opt/sbin/apache-httpd
httpd: bad user name nobody
httpd: bad user name nobody
postinst script returned status 1
ERROR: apache.postinst returned 1
Configuring bzip2
update-alternatives: Linking //opt/bin/bzip2 to /opt/bin/bzip2-bzip2
Configuring e2fsprogs
update-alternatives: Linking //opt/bin/chattr to /opt/bin/e2fsprogs-chattr
update-alternatives: Linking //opt/bin/lsattr to /opt/bin/e2fsprogs-lsattr
update-alternatives: Linking //opt/sbin/fsck to /opt/sbin/e2fsprogs-fsck
Configuring libstdc++
Configuring mod-wsgi
Configuring ncursesw
Configuring python25
Successfully terminated.

テスト用スクリプトの作成

mod_wsgiで動かすテスト用スクリプトファイルを作成する。

# mkdir /share/Qweb/wsgi/
# vi /share/Qweb/wsgi/test.py

test.pyの中身は、下記になる。

#!/usr/bin/env python
def application(environ, start_response):
    status = '200 OK'
    response_headers = [('Content-type', 'text/plain')]
    start_response(status, response_headers)
    return ["It's works python!"]

mod_wsgi.confの作成

mod_wsgiの設定ファイルを作成する。

# vi /usr/local/apache/conf/extra/mod_wsgi.conf

mod_wsgi.confの中身は、下記になる。

LoadModule wsgi_module /opt/libexec/mod_wsgi.so
WSGIScriptAlias /wsgi/test "/share/Qweb/wsgi/test.py"
<Location "/share/Qweb/wsgi/test">
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
</Location>

apache.confの修正

apache.confに、mod_wsgi.confを読み込む。

# vi /usr/local/apache/conf/apache.conf

apache.confの1番最後の行に追記する。

Include conf/extra/mod_wsgi.conf

apacheの再起動

変更を反映するため、apacheを再起動する。

# /usr/local/apache/bin/apachectl -k restart

動作確認

Webブラウザから、"http://ドメイン名/wsgi/test" にアクセスすると

It's works python!

と表示される。