- 目录
- 从源代码安装
从源代码安装¶
源代码浏览器¶
在 lighttpd 1.4 git 仓库中查看源代码
源代码检出¶
有多种选项可以获取 lighttpd 源代码树。推荐使用 git。
- git:(推荐)
只读:$ git clone https://git.lighttpd.net/lighttpd/lighttpd1.4.git
开发者:$ git clone git+ssh://git@lighttpd.net/lighttpd/lighttpd1.4.git
# initial checkout git clone https://git.lighttpd.net/lighttpd/lighttpd1.4.git cd lighttpd1.4 # subsequent updates (to obtain latest source) #cd lighttpd1.4 git pull
- svn:(git 的替代方案)
# initial checkout svn checkout https://github.com/lighttpd/lighttpd1.4/trunk lighttpd1.4 cd lighttpd1.4 # subsequent updates (to obtain latest source) #cd lighttpd1.4 svn update
- 源代码发布/快照
https://download.lighttpd.net/lighttpd/# download and extract tarball latest=$(curl -s https://download.lighttpd.net/lighttpd/releases-1.4.x/latest.txt) curl -o "$latest.tar.xz" https://download.lighttpd.net/lighttpd/releases-1.4.x/"$latest.tar.xz" tar -xJf "$latest.tar.xz" cd $latest
构建先决条件¶
lighttpd 支持多种构建框架:automake、cmake、meson 和 scons。
请确保您已安装最新的开发工具和可用软件包,例如针对 automake- autoconf
- automake
- libtool
- m4
- pcre-devel / libpcre3-dev
- pkg-config
- openssl
- gnutls
- mbedtls
- nss
- wolfssl
更多详情请参阅 lighttpd INSTALL (请务必阅读)
根据您想要的功能,可能需要其他开发库:可选库
在大多数系统上,您需要安装库软件包的开发版本;仅有库本身是不够的!
在 Debian 上,您还可以使用 apt-get 来安装所有 lighttpd 构建依赖项:apt-get build-dep lighttpd
构建命令(示例)¶
automake
#cd lighttpd1.4 ./autogen.sh ./configure -C --prefix=/usr/local # ./configure --help for additional options make -j 4 make check #sudo make install
cmake
#cd lighttpd1.4 cmake -DCMAKE_INSTALL_PREFIX=/usr/local -Wno-dev . make -j 4 make test #sudo make install
meson
#cd lighttpd1.4 meson setup --buildtype debugoptimized --prefix /usr/local build cd build meson compile meson test #sudo meson install
scons
#cd lighttpd1.4 scons -j 4 build_static=1 build_dynamic=0 prefix=/usr/local #sudo scons -j 4 build_static=1 build_dynamic=0 prefix=/usr/local install
更完整功能的构建示例命令可能会参考 lighttpd scripts/ci-build.sh
此外,运行单元测试还有更多选项
交叉编译¶
automake 帮助:./configure --help
automake 示例:./configure --build=arm-linux --host=x86_64-pc-linux-gnu --prefix=/usr/local --disable-static --enable-shared
操作指南:在 arm64 上为 iOS 构建 lighttpd
发行版打包(外部示例)¶
Debian:debian/control
Fedora:lighttpd.spec
OpenWRT:net/lighttpd/Makefile
Debian:当前软件包:https://debian.lighttpd.net/
Debian:使用 Debian `dpkg-buildpackage` 为较旧的 Debian 系统构建软件包
(以下命令假定 debian/changelog 与最新的 lighttpd 版本匹配。请根据需要更改 $release
。)
release=$(curl -s https://download.lighttpd.net/lighttpd/releases-1.4.x/latest.txt) release=${release#*-} wget https://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-$release.tar.xz mv lighttpd-$release.tar.xz lighttpd_$release.orig.tar.xz git clone https://salsa.debian.org/debian/lighttpd.git cd lighttpd/ # For older Debian releases: head -1 debian/changelog # For older Debian releases: git checkout debian/1.4.76-1 # For older Debian releases: edit top line of debian/changelog to match top line from `head -1 debian/changelog` above dpkg-buildpackage -uc -us cd .. ls lighttpd*_$release*.deb # dpkg -i ...
要在没有
debputy
的旧版 Debian 上构建,请从 salsa.debian.org/debian/lighttpd.git 检出旧标签,然后修改 debian/changelog 的第一行以匹配 $release
版本
从构建目录运行 lighttpd¶
lighttpd 可以直接从构建目录运行,无需安装。这对于测试很有用。在您构建 lighttpd 的 shell 中,进入源代码树的根目录(如果尚未进入)。
创建一个基本的 lighttpd.conf 文件,使其监听 localhost 端口 8080 并从 /tmp
提供文件(不建议用于生产环境!)
server.document-root = "/tmp" server.bind = "127.0.0.1" server.port = 8080 mimetype.assign = (".txt" => "text/plain", ".html" => "text/html" )
创建一个简单的文件以供服务:
echo "Hello World!" > /tmp/hello.txt
在前台运行 lighttpd:
src/lighttpd -D -f lighttpd.conf -m $PWD/src/.libs
在另一个 shell 中:
curl http://127.0.0.1:8080/hello.txt
在运行 lighttpd 的 shell 中,按
Ctrl-C
使 lighttpd 退出。
自 lighttpd 1.4.60 起,lighttpd 配置可以选择从标准输入指定(但与一次性模式(-1
)不兼容)echo -e 'server.document-root="/tmp"\n server.port=8080' | src/lighttpd -D -m $PWD/src/.libs -f -
自 lighttpd 1.4.70 起,可以选择使用 shell HERE 文档来指定 lighttpd 配置
src/lighttpd -D -m $PWD/src/.libs -f <(cat <<END server.document-root = "/tmp" server.port = 8080 END )
信号¶
lighttpd 响应以下信号
- SIGTERM - 立即关闭(终止现有连接,然后退出)
- SIGINT - 平滑关闭(服务现有连接,然后退出)
- SIGUSR1 - 平滑重载(服务现有连接,然后重载配置)
- SIGHUP - 重新打开日志文件(注意:不重新加载 lighttpd 配置)
(注意:SIGUSR1 行为在 lighttpd 1.4.46 及更高版本中可用)
平滑重启¶
在 lighttpd 1.4.46 及更高版本中,SIGUSR1 是平滑处理配置重新加载的推荐方法,但对于使用 chroot 的 lighttpd 配置,仍然需要先平滑停止再重新启动 lighttpd。
在 lighttpd 1.4.56 及更高版本中,平滑重启可以对现有活动连接施加时间限制,然后服务器再重新加载配置:(server.feature-flags)server.feature-flags = ( "server.graceful-shutdown-timeout" => 5 )
在某些配置中,lighttpd 可以立即重启,而服务器的一个分支副本继续服务现有连接(效果可能因人而异)server.feature-flags = ( "server.graceful-shutdown-timeout" => 5, "server.graceful-restart-bg" => "enable" )
server.systemd-socket-activation = "enable"
归档:2005 年的一篇旧文章讨论了使用 SIGINT 进行平滑重启:https://blog.lighttpd.ac.cn/articles/2005/09/02/graceful-restart/
init 脚本¶
根据操作系统和发行版品牌,有多种方法可以将 lighttpd 设置为在系统启动时作为守护进程运行,并向 lighttpd 发送启动/停止/重启等信号。与其试图为未知数量的发行版维护脚本,这里提供了一些链接,可用作示例。
- Arch:https://gitlab.archlinux.org/archlinux/packaging/packages/lighttpd
- Debian:https://salsa.debian.org/debian/lighttpd
- Fedora:https://src.fedoraproject.org/rpms/lighttpd/tree/rawhide
- FreeBSD:https://cgit.freebsd.org/ports/tree/www/lighttpd
- Gentoo:https://gitweb.gentoo.org/repo/gentoo.git/tree/www-servers/lighttpd/
- openSUSE:https://build.opensuse.org/package/show/server:http/lighttpd
- OpenWRT:https://github.com/openwrt/packages/tree/master/net/lighttpd
systemd 单元脚本示例 lighttpd.service
进程监控¶
作为 init 脚本的替代方案,您可以使用 daemontools 或 runit 设置一个“受监控”的 lighttpd,请参阅 LighttpdUnderSupervise
xinetd¶
- 从 xinetd 运行 lighttpd,让 lighttpd 继续接受连接,并在 lighttpd 空闲 10 分钟后退出。
/etc/lighttpd/lighttpd.conf (示例)
server.document-root = "/var/www" server.bind = "/dev/stdin"
/etc/xinetd.d/lighttpd (示例)
service lighttpd { socket_type = stream protocol = tcp port = 80 type = http wait = yes user = lighttpd server = /usr/sbin/lighttpd server_args = -D -f /etc/lighttpd/lighttpd.conf -i 600 }
- 从 xinetd 运行 lighttpd,让 lighttpd 服务单个连接(包括保持连接请求),然后退出。
/etc/lighttpd/lighttpd.conf (示例)
server.document-root = "/var/www"
/etc/xinetd.d/lighttpd (示例)
service lighttpd { socket_type = stream protocol = tcp port = 80 type = http wait = no user = lighttpd server = /usr/sbin/lighttpd server_args = -D -f /etc/lighttpd/lighttpd.conf -1 }
netcat¶
- 通过 netcat 或 ncat 或 nc 运行 lighttpd
/etc/lighttpd/lighttpd.conf (示例)
server.document-root = "/var/www"
netcat 命令
ncat -l 8080 -e "/usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf -1"
shell 管道¶
- 在 shell 管道中运行 lighttpd
/etc/lighttpd/lighttpd.conf (示例)
server.document-root = "/var/www"
一个或多个请求的 shell 管道
printf "GET /index.txt HTTP/1.1\r\nHost: example.com\r\n\r\n" | /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -1
valgrind¶
lighttpd 可以在 valgrind
下运行以测试内存泄漏。下面 valgrind.supp
抑制文件示例用于抑制底层 glibc 中的内存泄漏,这些并非 lighttpd 中的内存泄漏。
valgrind --suppressions=valgrind.supp --leak-check=full --show-leak-kinds=all lighttpd -D -f /etc/lighttpd/lighttpd.conf
# lighttpd valgrind.supp (note: ... should be copied literally) { Ignore dlopen bug Memcheck:Leak ... fun:_dl_open ... } { Ignore _dlerror_run bug Memcheck:Leak ... fun:_dlerror_run ... }
KDE 中类似的 valgrind 讨论:https://bugs.kde.org/show_bug.cgi?id=358980