web.pyをlighttpdで動かす

wsgiでは動かせないんだっけ?
設定サンプルでは、FastCGIになっているのでそれでやる。

debian:/# apt-get install lighttpd
Reading package lists... Done
Building dependency tree... Done
The following extra packages will be installed:
  libpcre3
Suggested packages:
  openssl rrdtool apache2-utils
Recommended packages:
  php4-cgi php5-cgi
The following NEW packages will be installed:
  libpcre3 lighttpd
0 upgraded, 2 newly installed, 0 to remove and 2 not upgraded.
Need to get 454kB of archives.
After unpacking 1102kB of additional disk space will be used.
Do you want to continue [Y/n]?
Get:1 http://security.debian.org etch/updates/main lighttpd 1.4.13-4etch1 [288kB]
Get:2 http://ftp.debian.org etch/main libpcre3 6.7-1 [166kB]
Fetched 454kB in 7s (62.2kB/s)

fastcgiを有効にする。
なんか、PHPはconf-available/10-fastcgi.conf内に設定が書いてあるな...
普通は、

debian:/# ln -s /etc/lighttpd/conf-available/10-fastcgi.conf /etc/lighttpd/conf-enabled/

するのだけど、今回は、mod_rewriteを有効にして、その設定も書かなくてはいけないので専用の設定ファイルを作ったほうが良さそう。

debian:/# cp /etc/lighttpd/conf-available/10-fastcgi.conf /etc/lighttpd/conf-available/10-
webpy.conf
debian:/# vi /etc/lighttpd/conf-available/10-webpy.conf
## pyctures and web.py settings

#server.modules   += ( "mod_fastcgi", "mod_rewrite")
server.modules   += ( "mod_fastcgi" )

url.redirect = (
    "^/pics$" => "/pics/"
)

fastcgi.server = (
    "/pics" => ((
        "socket" => "/tmp/fastcgi-pics.socket",
        "bin-path" => "/var/www/pyctures/pyctures",
        "max-procs" => 1,
        "check-local" => "disable"
    ))
)
debian:/# ln -s /etc/lighttpd/conf-available/10-webpy.conf /etc/lighttpd/conf-enabled/

最後の行の有効化設定は、正統派の作法ではこうするみたい。

debian:/# lighty-enable-mod
Available modules: auth cgi fastcgi proxy simple-vhost ssi ssl userdir webpy
Already enabled modules:
Enable module: webpy
Enabling webpy: ok
Run /etc/init.d/lighttpd force-reload to enable changes

アプリは/rootの配下、データは/home/alubmに置いているが、この場所はあんまりなので移動する。ファイルの所有権も変更。

debian:/# mkdir /var/www/pictures/
debian:/# cp -a /root/pyctures-0.20/website/* /var/www/pictures/
debian:/# cp -a /home/albums /var/www/pictures/
debian:/# chown -R www-data.www-data /var/www/

んで、起動してみる。

debian:/# /etc/init.d/lighttpd start
Starting web server: lighttpd.
debian:/# Traceback (most recent call last):
  File "/var/www/pyctures", line 19, in ?
    web.run(urls.urls, web.reloader)
  File "/root/pyctures-0.20/website/web/request.py", line 147, in run
    return wsgi.runwsgi(webapi.wsgifunc(webpyfunc(inp, fvars, autoreload), *middleware))
  File "/root/pyctures-0.20/website/web/wsgi.py", line 35, in runwsgi
    return runfcgi(func, None)
  File "/root/pyctures-0.20/website/web/wsgi.py", line 16, in runfcgi
    import flup.server.fcgi as flups
ImportError: No module named flup.server.fcgi
|<<
あ、web.pyって、flupが必要なのね...
>||
debian:/# apt-get install python-flup
Reading package lists... Done
Building dependency tree... Done
Recommended packages:
  python-webpy
The following NEW packages will be installed:
  python-flup
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 65.1kB of archives.
After unpacking 430kB of additional disk space will be used.
Get:1 http://ftp.debian.org etch/main python-flup 0.2126-1 [65.1kB]
Fetched 65.1kB in 1s (41.7kB/s)
debian:/# /etc/init.d/lighttpd restart
Stopping web server: lighttpd.
Starting web server: lighttpd.

起動した。
ブラウザからもちゃんと見える。
サイズの大きいメイン写真はともかく、それ以外はそこそこのスピードで表示されている。
高速化検討の必要はなさそうだ。