【Lighttpd】conda-forge版でLighttpdに入門してみる【Pixi】
手探りでLighttpd を始める
一つとして記事がないらしいが(あった)、
低負荷、高速、安全、柔軟などと謳われているものの、
にも拘わらず
0. Pixi 導入
curl -fsSL https://pixi.sh/install.sh | sh
# あるいは
wget -qO- https://pixi.sh/install.sh | sh
1. Lighttpd 導入
ワークスペースを作り、この中に
ワークスペース作成
# ワークスペース作成
$ pixi init lighty_sample
✔ Created /⋯/lighty_sample/pixi.toml
# 移動
$ cd lighty_sample/
インストール
$ pixi add lighttpd
✔ Added lighttpd >=1.4.73,<2
仮想環境
.pixi/env配下に仮想環境defaultが自動的に作られる。
$ ls .pixi/envs/
default
$ ls .pixi/envs/default/
bin conda-meta etc include lib libexec man sbin share ssl
実環境と同様etcフォルダーが存在するが、その中にlighttpdというフォルダーは存在しないことに注意。
$ ls .pixi/envs/default/etc/
conda openldap pkcs11 request-key.conf
2. 設定
こちらの記事を見ると、通常は/etc/lighttpd/lighttpd.confという設定ファイルがあるらしい。
しかし上述の通り、仮想環境下に/etc/lighttpd/は存在しないため、そこから想像つくようにlighttpd.confも存在しないようである。
$ find .pixi/envs/default/ -name '*.conf'
.pixi/envs/default/share/examples/krb5/kdc.conf
.pixi/envs/default/share/examples/krb5/krb5.conf
.pixi/envs/default/etc/request-key.conf
.pixi/envs/default/etc/openldap/ldap.conf
設定ファイルを作る
ないものを嘆いても仕方ないのだから、自分で作らなければならない。
整理のため、lighttpdフォルダーを作っておく。この中にlighttpd.confを次の内容で作る。
server.modules = ( "mod_staticfile" )
server.document-root = "/⋯/lighty_sample/var/www/"
server.port = 8080
先の記事を真似して、var/www/フォルダーにindex.htmlを配置することとした。ここでは/⋯/lighty_sample/var/www/抔と、⋯で一部省略しているが、実際には完全な絶対パスを記載しなければならない点に注意。
3. 動作確認
設定ファイルを作ったら、
index.html
適当に作ってもよいが、今回は
起動方法
lighttpdコマンドで-Dを付する。また設定ファイルを-fで指定する。その他オプションは次の通り。
$ pixi run lighttpd --help
/⋯/lighty_sample/.pixi/envs/default/bin/lighttpd: invalid option -- '-'
lighttpd/1.4.73 (ssl) - a light and fast webserver
usage:
-f <name> filename of the config-file
-m <name> module directory (default: /⋯/lighty_sample/.pixi/envs/default/lib)
-i <secs> graceful shutdown after <secs> of inactivity
-1 process single (one) request on stdin socket, then exit
-p print the parsed config-file in internal form, and exit
-t test config-file syntax, then exit
-tt test config-file syntax, load and init modules, then exit
-D don't go to background (default: go to background)
-v show version
-V show compile-time features
-h show this help
ここでは、次のコマンドで実行することとなる。
lighttpd -D -f lighttpd/lighttpd.conf
タスクの使用(Pixi )
以上の話を全てタスクに落とし込むと、次のように書ける。
[workspace]
channels = ["conda-forge"]
name = "lighty_sample"
platforms = ["linux-64"]
version = "0.1.0"
[tasks]
_mkdir_tmp = "mkdir -p .pixi/envs/default/tmp"
_mkdir_var_www = "mkdir -p var/www"
start = { cmd = "lighttpd -D -f lighttpd/lighttpd.conf", depends-on = ["_mkdir_tmp", "_install_default_html"] }
test = "lighttpd -t"
[tasks._install_default_html]
cmd = "wget https://raw.githubusercontent.com/lighttpd/lighttpd1.4/refs/heads/master/tests/docroot/index.html"
cwd = "var/www"
depends-on = ["_mkdir_var_www"]
outputs = ["index.html"]
[dependencies]
lighttpd = ">=1.4.73,<2"
この設定によって、全ての作業を次のコマンド一つに任せることができた。
$ pixi run start
http://127.0.0.1:8080/index.htmlにアクセスすれば、テストページが表示される。しかし、画像など不足しているようだった。

Discussion