Ubuntu 22.04 安装 Lighttpd 指南

Ubuntu 22.04.5 上 Lighttpd 双方案安装实录:apt 软件源 1.4.63 与官方源码 meson 编译最新稳定 1.4.85,systemd 托管、模块启停、改端口验证、端口占用排障与升级卸载,回显全部实测(2026-10-20)。

LighttpdLighttpdUbuntu网络配置2026/10/21

Ubuntu 22.04 安装 Lighttpd 指南

目标:在 Ubuntu 22.04.5 LTS 上完成 lighttpd 的完整安装与 systemd 托管,覆盖两条路线——方案 A 使用 Ubuntu 软件源(apt,版本 1.4.63,稳定省心)、方案 B 使用官方源码编译(最新稳定版 1.4.85,2026-10-20 官方实查);全部命令与回显均为真实环境实测照抄,含端口占用排障与升级卸载实录。

一、环境信息

本文所有命令在以下环境实测执行,回显逐行照抄:

  • 操作系统:Ubuntu 22.04.5 LTS(x86_64,PRETTY_NAME="Ubuntu 22.04.5 LTS")
  • 内核网络视角:lighttpd 默认监听 80 端口;本文实测环境中同时演示改绑 8080 端口的完整流程
  • 方案 A 软件版本:lighttpd 1.4.63-1ubuntu3.1(jammy-updates/universe)
  • 方案 B 软件版本:lighttpd 1.4.85(官方最新稳定版,发布于 2026-07-08,download.lighttpd.net/lighttpd/releases-1.4.x/latest.txt 实查)
  • 编译工具链:gcc 11.4.0、meson 0.61.2、ninja 1.10.1
  • 域名:本文用 localhost 直连验证;无域名依赖

二、前置条件

  1. 一台 Ubuntu 22.04 主机,具备 sudo 权限账号(本文实测以 root 执行,普通用户请自行加 sudo)。
  2. 软件源可达(方案 A 需要 archive.ubuntu.com;方案 B 需要 download.lighttpd.net)。
  3. 80 端口(或你计划使用的端口)未被占用。判定方法:先停掉/未装 lighttpd 时请求本机 80 端口,curl 返回码为 7(连接被拒)即端口空闲:
curl -sI --max-time 3 http://localhost/ ; echo "curl-rc=$?"

端口空闲时实测回显(无任何响应头,返回码 7 表示 Connection refused):

curl-rc=7
  1. 确认系统版本与架构:
grep PRETTY /etc/os-release

实测回显:

PRETTY_NAME="Ubuntu 22.04.5 LTS"

三、版本选型说明

Ubuntu 22.04 软件源的 lighttpd 与官方最新稳定版存在代差,先看清楚再选:

对比项方案 A:Ubuntu 软件源(apt)方案 B:官方源码编译
版本1.4.63-1ubuntu3.11.4.85(官方最新稳定,2026-07-08 发布)
安全更新由 Ubuntu jammy-updates 通道维护需自行跟踪官方发布并重新编译
安装难度一条命令,自动注册 systemd 服务需安装工具链,自行编写 systemd 单元
安装路径/usr/sbin/lighttpd,配置在 /etc/lighttpd//usr/local/lighttpd/(前缀自定)
与其他服务共存系统级统一管理独立目录,互不干扰
适用人群生产环境大多数场景需要新版本特性(mod_h2 HTTP/2 增强、新修复)或定制编译特性

软件源内版本实查(方案 A 安装前可先执行确认):

apt-cache policy lighttpd

实测回显:

lighttpd:
  Installed: (none)
  Candidate: 1.4.63-1ubuntu3.1
  Version table:
     1.4.63-1ubuntu3.1 500
        500 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages
        100 /var/lib/dpkg/status
     1.4.63-1ubuntu3 500
        500 http://archive.ubuntu.com/ubuntu jammy/universe amd64 Packages

官方最新版本实查(2026-10-20):https://download.lighttpd.net/lighttpd/releases-1.4.x/latest.txt 内容为 lighttpd-1.4.85;官方 sha256sum 文件给出 lighttpd-1.4.85.tar.xz 校验值 18de51b393bac4a6827879e1a7ff377c169e414bae92cd245091d80fc2601d13。

选型建议:没有明确的新版本特性需求,直接用方案 A;方案 B 适合「要用 1.4.7x+ 的 mod_h2 HTTP/2 新形态、需要裁剪模块、或者 apt 版有已知 bug 正等待官方修复」的读者。

四、方案 A:Ubuntu 软件源在线安装(apt)

本方案一条命令完成安装,安装包会自动注册并启动 systemd 服务 lighttpd.service。

4.1 安装

apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y lighttpd

关键回显(节选,完整输出较长已省略与主题无关的行):

Setting up lighttpd (1.4.63-1ubuntu3.1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/lighttpd.service → /lib/systemd/system/lighttpd.service.

解读:Created symlink ... multi-user.target.wants/lighttpd.service 表明安装器已自动设置开机自启;真实服务器上此时 80 端口已在服务。

4.2 版本与服务状态确认

lighttpd -v && systemctl is-active lighttpd && systemctl is-enabled lighttpd

实测回显:

lighttpd/1.4.63 (ssl) - a light and fast webserver
active
enabled

systemctl status(--no-pager 参数用于非交互终端):

systemctl status lighttpd --no-pager

实测回显(节选):

● lighttpd.service - Lighttpd Daemon
     Loaded: loaded (/lib/systemd/system/lighttpd.service; enabled; preset: enabled)
     Active: active (running) since Mon 2026-10-20 16:25:39 UTC; 1min 12s ago
    Process: 1659 ExecStartPre=/usr/sbin/lighttpd -tt -f /etc/lighttpd/lighttpd.conf (code=exited, status=0/SUCCESS)
   Main PID: 1661 (lighttpd)
     Memory: 2.4M
        CPU: 33ms

解读三点:① ExecStartPre=... -tt 说明每次启动前 systemd 会先做配置语法自检,配置错误会在这里暴露;② 常驻内存实测 2.4M,印证 lighttpd 的轻量定位;③ 服务单元文件内容如下(Ubuntu 自带,了解它有助于理解启动流程):

cat /lib/systemd/system/lighttpd.service

实测回显:

[Unit]
Description=Lighttpd Daemon
After=network-online.target

[Service]
Type=simple
PIDFile=/run/lighttpd.pid
ExecStartPre=/usr/sbin/lighttpd -tt -f /etc/lighttpd/lighttpd.conf
ExecStart=/usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf
ExecReload=/bin/kill -USR1 $MAINPID
Restart=on-failure

[Install]
WantedBy=multi-user.target

4.3 HTTP 验证

curl -sI http://localhost

实测回显:

HTTP/1.1 200 OK
Content-Type: text/html
ETag: "772211268"
Last-Modified: Tue, 20 Oct 2026 16:23:42 GMT
Content-Length: 3371
Accept-Ranges: bytes
Date: Tue, 20 Oct 2026 16:24:26 GMT
Server: lighttpd/1.4.63

默认站点根目录为 /var/www/html,安装时放入的占位页是 /var/www/html/index.lighttpd.html。替换为你自己的首页并验证:

echo '<h1>hello lighttpd</h1>' > /var/www/html/index.html
curl -s http://localhost

实测回显:

<h1>hello lighttpd</h1>

⚠️ 注意:默认配置 index-file.names = ( "index.php", "index.html" )(见 /etc/lighttpd/lighttpd.conf),所以放 index.html 即可覆盖占位页;不要删占位文件以外的默认配置项。

4.4 配置目录与模块管理

Ubuntu 把 lighttpd 配置拆成「主配置 + 模块片段 + 启用软链」三层:

ls /etc/lighttpd/

实测回显:

conf-available  conf-enabled  lighttpd.conf

可用模块片段(28 个文件,ls /etc/lighttpd/conf-available/ 节选):

10-accesslog.conf  10-access.conf  10-alias.conf  10-cgi.conf
10-dir-listing.conf  10-evasive.conf  10-fastcgi.conf  10-flv-streaming.conf
10-no-www.conf  10-php.conf  10-proxy.conf  10-redirect.conf
10-rewrite.conf  10-rrdtool.conf  10-ssi.conf  10-status.conf
10-userdir.conf  10-usertrack.conf  15-fastcgi-php.conf  90-debian-doc.conf
99-unconfigured.conf  README  README.FastCGI  lighttpd-nginx.conf

启用/停用模块用发行版自带的 lighty-enable-mod / lighty-disable-mod(同目录另有 lighttpd-enable-mod、lighttpd-disable-mod 等价别名),以启用 cgi 模块为例:

lighty-enable-mod cgi

实测回显:

Enabling cgi: ok
Run "service lighttpd force-reload" to enable changes

生成的软链与重载:

ls -l /etc/lighttpd/conf-enabled/ | grep cgi && service lighttpd force-reload && echo RELOAD-OK

实测回显:

lrwxrwxrwx 1 root root 35 Oct 20 16:36 10-cgi.conf -> ../conf-available/10-cgi.conf
RELOAD-OK

💡 说明:service lighttpd force-reload 成功时静默(无输出、返回 0),所以用 && 链验证返回码;systemctl reload lighttpd 等价(单元文件里 ExecReload=/bin/kill -USR1 $MAINPID,即向主进程发 USR1 做优雅重启,不停机加载新配置)。

不用的模块随手关掉,保持配置面干净:

lighty-disable-mod cgi

实测回显:

Disabling cgi
Run "service lighttpd force-reload" to enable changes

4.5 改绑端口(80 → 8080)实测

Ubuntu 默认配置中监听端口由主配置的 server.port 控制,把它改成 8080 并重启验证:

sed -i 's/^server.port.*/server.port                 = 8080/' /etc/lighttpd/lighttpd.conf
grep '^server.port' /etc/lighttpd/lighttpd.conf
systemctl restart lighttpd && systemctl is-active lighttpd

实测回显:

server.port                 = 8080
active

验证新端口(注意 80 端口此时已不再响应):

curl -sI http://localhost:8080

实测回显:

HTTP/1.1 200 OK
Content-Type: text/html
ETag: "772211268"
Last-Modified: Tue, 20 Oct 2026 16:23:42 GMT
Content-Length: 3371
Accept-Ranges: bytes
Date: Tue, 20 Oct 2026 16:54:33 GMT
Server: lighttpd/1.4.63

错误日志同时记录了本次启动:

tail -1 /var/log/lighttpd/error.log

实测回显:

2026-10-20 16:54:17: (server.c.1551) server started (lighttpd/1.4.63)

五、方案 B:官方源码编译安装(最新稳定版 1.4.85)

本方案在 Ubuntu 22.04 上从官方源码编译安装 lighttpd 1.4.85,安装到独立前缀 /usr/local/lighttpd,并用 systemd 托管为 lighttpd-local.service。

5.1 安装编译依赖

1.4.8x 官方推荐用 meson + ninja 构建(源码包内无现成 ./configure,如需 autotools 需先跑 autogen.sh,本文按官方推荐路径走 meson)。需要的基础库:pcre2(URL 正则)、zlib/zstd/brotli(压缩)、libssl(TLS):

apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
  build-essential libpcre2-dev zlib1g-dev libbz2-dev libssl-dev \
  libzstd-dev libbrotli-dev meson ninja-build pkg-config wget

安装完成确认工具链版本:

gcc --version | head -1 && meson --version && ninja --version

实测回显:

gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
0.61.2
1.10.1

5.2 下载源码并校验

cd /root
wget https://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.85.tar.xz
sha256sum lighttpd-1.4.85.tar.xz

实测回显:

-rw-r--r-- 1 root root 897120 Jul  9 02:38 lighttpd-1.4.85.tar.xz
18de51b393bac4a6827879e1a7ff377c169e414bae92cd245091d80fc2601d13  lighttpd-1.4.85.tar.xz

校验点:sha256 值与官方 lighttpd-1.4.85.sha256sum 文件中 lighttpd-1.4.85.tar.xz 一致(文件大小 897120 字节,即约 876 KiB)。

5.3 解压与 meson 配置

tar xf lighttpd-1.4.85.tar.xz
cd lighttpd-1.4.85
meson setup build --prefix=/usr/local/lighttpd -Dwith_openssl=true -Dwith_zstd=enabled -Dwith_brotli=enabled

实测回显(尾部):


  User defined options
    prefix      : /usr/local/lighttpd
    with_brotli : enabled
    with_openssl: true
    with_zstd   : enabled

Found ninja-1.10.1 at /usr/bin/ninja

⚠️ 注意(实测踩坑记录):meson 特性开关有两种取值类型——with_openssl 是布尔型(true/false),with_zstd/with_brotli 是三态组合型(enabled/disabled/auto),写成 -Dwith_openssl=enabled 或 -Dwith_zstd=true 都会直接报错终止;另外 Ubuntu 22.04 最小安装环境默认不带 libzstd-dev/libbrotli-dev 头文件时,即便开关打开也会被静默跳过(配置摘要显示 Dependency libzstd skipped: feature with_zstd disabled),最终 lighttpd -V 里看不到 +zstd/+brotli。要完整压缩特性,务必先装齐头文件再重新 meson setup。

5.4 编译与安装

ninja -C build

实测回显(尾部):

[178/179] Compiling C object src/lighttpd.p/server.c.o
[179/179] Linking target src/lighttpd
ninja -C build install

实测回显(尾部):

Installing src/mod_webdav.so to /usr/local/lighttpd/lib/lighttpd
Installing src/mod_wstunnel.so to /usr/local/lighttpd/lib/lighttpd
Installing src/mod_openssl.so to /usr/local/lighttpd/lib/lighttpd
Installing /root/lighttpd-1.4.85/doc/lighttpd.8 to /usr/local/lighttpd/share/man/man8
Installing /root/lighttpd-1.4.85/doc/lighttpd-angel.8 to /usr/local/lighttpd/share/man/man8

安装完成后的目录结构与二进制体积:

ls /usr/local/lighttpd/ && ls -l /usr/local/lighttpd/sbin/lighttpd

实测回显:

etc
lib
sbin
share
var
-rwxr-xr-x 1 root root 1685112 Oct 20 16:31 /usr/local/lighttpd/sbin/lighttpd

💡 说明:etc、var 两个目录 meson 不会自动创建,但首次用 -f 指定这里的配置启动时需手工准备(下文 5.5 直接创建);lib/lighttpd/ 下是动态模块(本文构建共 19 个 .so),share/man/man8/ 是手册页。

版本与特性确认(对比方案 A 的 1.4.63):

/usr/local/lighttpd/sbin/lighttpd -v && /usr/local/lighttpd/sbin/lighttpd -V | grep -E "OpenSSL|zstd|brotli|epoll"

实测回显:

lighttpd/1.4.85 (ssl) - a light and fast webserver
        + epoll (Linux)
        + zlib support
        + zstd support
        + brotli support
        + OpenSSL support

5.5 编写最小配置

编译版没有发行版配置体系,自己写最小配置(监听 80、站点根 /var/www/html):

mkdir -p /usr/local/lighttpd/etc /usr/local/lighttpd/var/run /usr/local/lighttpd/var/log
cat > /usr/local/lighttpd/etc/lighttpd-local.conf <<'EOF'
server.modules = ( "mod_accesslog" )
server.document-root = "/var/www/html"
server.bind = "0.0.0.0"
server.port = 80
server.pid-file = "/usr/local/lighttpd/var/run/lighttpd-local.pid"
server.errorlog = "/usr/local/lighttpd/var/log/error-local.log"
accesslog.filename = "/usr/local/lighttpd/var/log/access-local.log"
index-file.names = ( "index.html" )
mimetype.assign = ( ".html" => "text/html" )
EOF

启动前先做语法检查(-tt 会连模块一起加载验证):

/usr/local/lighttpd/sbin/lighttpd -tt -f /usr/local/lighttpd/etc/lighttpd-local.conf && echo CONFIG-TEST-OK

实测回显:

CONFIG-TEST-OK

5.6 systemd 托管(编译版)

写一个独立命名的服务单元 lighttpd-local.service,与 apt 版 lighttpd.service 并存不冲突(若同时安装了方案 A,先 systemctl stop lighttpd 释放 80 端口):

cat > /etc/systemd/system/lighttpd-local.service <<'EOF'
[Unit]
Description=lighttpd 1.4.85 (compiled from source)
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/lighttpd/sbin/lighttpd -D -f /usr/local/lighttpd/etc/lighttpd-local.conf
ExecReload=/bin/kill -USR1 $MAINPID
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF
systemctl stop lighttpd
systemctl daemon-reload
systemctl enable lighttpd-local

实测回显(enable 一条):

Created symlink /etc/systemd/system/multi-user.target.wants/lighttpd-local.service → /etc/systemd/system/lighttpd-local.service.

启动并验证:

systemctl start lighttpd-local && systemctl is-active lighttpd-local
curl -sI http://localhost | grep -E "HTTP|Server|Content-Length"

实测回显(站点根下已放置测试页 <h1>lighttpd 1.4.85 local build</h1>):

active
HTTP/1.1 200 OK
Content-Length: 37
Server: lighttpd/1.4.85

确认无异常后把方案 A 的服务恢复(如两套并存需要区分端口,可改 lighttpd-local.conf 的 server.port):

systemctl stop lighttpd-local && systemctl start lighttpd && systemctl is-active lighttpd

实测回显:

active

六、方案对比与选择建议

关注点建议
生产默认选方案 A:版本虽旧但随 jammy-updates 获得安全修复,运维成本最低
想要 HTTP/2 / 最新修复选方案 B:1.4.85 的 mod_h2 线领先 apt 版两个大版本段
多实例并存方案 B 独立前缀 /usr/local/lighttpd 更干净;两套并存时用 lighttpd.service 与 lighttpd-local.service 区分,注意 80 端口只能归一个所有
配置体系方案 A 有 conf-available/conf-enabled 模块片段机制;方案 B 需自管理单文件配置
升级方式方案 A:apt-get install --only-upgrade lighttpd;方案 B:下载新版源码重复 5.2–5.4,前缀覆盖安装

七、配置说明

安装后首当其冲的是主配置文件 /etc/lighttpd/lighttpd.conf(方案 A)。全文结构如下(实测内容,注释已省略):

server.modules = (
        "mod_indexfile",
        "mod_access",
        "mod_alias",
        "mod_redirect",
)

server.document-root        = "/var/www/html"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"
server.port                 = 80

# strict parsing and normalization
server.http-parseopts = (
  "header-strict"           => "enable",# default
  "host-strict"             => "enable",# default
  "host-normalize"          => "enable",# default
  "url-normalize-unreserved"=> "enable",# RFC 3986 percent-encoded unreserved characters
  "url-normalize-required"  => "enable",# RFC 3986 percent-encoded reserved characters
  "url-ctrls-reject"        => "enable",# control chars (space) in url
  "url-path-2f-decode"      => "disable"# decode %2f to /
)

index-file.names            = ( "index.php", "index.html" )
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/javascript", "text/css", "text/html", "text/plain" )

# default listening port for IPv6 falls back to the IPv4 port
## Use ipv6 if available
#include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

要点解读(均为 Ubuntu 打包行为的实测观察):

  1. 进程身份:server.username/groupname = "www-data",lighttpd 以 root 绑定 80 后降权到 www-data 运行;上传临时目录 /var/cache/lighttpd/uploads 归 www-data 所有。
  2. 安全加固默认开启:server.http-parseopts 一组是对请求 URL/header 的规范化与拒绝策略(1.4.5x+ 引入),保持默认即可。
  3. PHP 入口已留好:index-file.names 含 index.php 且 static-file.exclude-extensions 排除了 .php,启用 15-fastcgi-php.conf 片段后即可对接 PHP(lighty-enable-mod fastcgi-php)。
  4. 模块生效机制:include-conf-enabled.pl 负责把 conf-enabled/ 下所有片段带进主配置——这就是 lighty-enable-mod 只创建软链、再 force-reload 即生效的原因。
  5. 日志轮转:/etc/logrotate.d/lighttpd 已随包安装(对 error.log/access.log 按 weekly 轮转),无需手工配置。

方案 B 的最小配置逐项含义见 5.5 与 C1 配置参数详解篇(同专栏),核心等价关系:server.document-root ↔ 站点根、server.port ↔ 监听端口、server.errorlog/accesslog.filename ↔ 日志位置。

八、常见问题(FAQ)

Q1:systemctl restart lighttpd 后服务变 failed,日志报 can't bind to socket ... Address already in use

根因:80 端口被其他进程占用。实测复现:在本机 80 端口起了一个测试进程后再重启 lighttpd,服务失败:

systemctl status lighttpd --no-pager

实测回显(节选):

● lighttpd.service - Lighttpd Daemon
     Loaded: loaded (/lib/systemd/system/lighttpd.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Mon 2026-10-20 16:26:37 UTC; 7s ago
    Process: 2040 ExecStartPre=/usr/sbin/lighttpd -tt -f /etc/lighttpd/lighttpd.conf (code=exited, status=0/SUCCESS)
    Process: 2050 ExecStart=/usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf (code=exited, status=255/EXCEPTION)
   Main PID: 2050 (code=exited, status=255/EXCEPTION)
journalctl -u lighttpd --no-pager -n 4

实测回显:

Oct 20 16:26:35 ubuntu systemd[1]: Starting Lighttpd Daemon...
Oct 20 16:26:35 ubuntu lighttpd[2050]: 2026-10-20 16:26:35: (server.c.1494) can't bind to socket: 0.0.0.0:80: Address already in use
Oct 20 16:26:35 ubuntu systemd[1]: lighttpd.service: Main process exited, code=exited, status=255/EXCEPTION
Oct 20 16:26:37 ubuntu systemd[1]: lighttpd.service: Failed with result 'exit-code'.

处置:用 ss -ltnp 'sport = :80' 找到占用进程并停掉,或按 4.5 改 server.port;随后 systemctl reset-failed lighttpd && systemctl restart lighttpd 恢复(实测恢复后 is-active 返回 active,curl -sI http://localhost 返回 HTTP/1.1 200 OK)。

Q2:启用模块提示 Run "service lighttpd force-reload",执行后没输出,是失败了吗?

不是。force-reload 成功时静默返回 0(见 4.4 实测,用 && echo RELOAD-OK 链验证返回码)。若想看到具体动作,用 journalctl -u lighttpd --no-pager -n 3 查看重载日志。

Q3:改了配置重启后还是旧行为?

先用 lighttpd -tt -f /etc/lighttpd/lighttpd.conf 做语法自检(有错会逐行指出文件与行号),再确认改的是 /etc/lighttpd/lighttpd.conf 而非 conf-available/ 里的未启用片段;conf-enabled/ 才是生效集合(软链目录,见 4.4)。

Q4:404 页面被 error-handler 替换后返回 200?

这是 lighttpd 对「静态文件作为 server.error-handler-404」的既有行为:处理页自身的状态码(200)会成为响应状态码(在 1.4.85 编译版实测:请求不存在路径返回 HTTP/1.1 200 OK 并输出处理页内容)。需要保持 404 状态码时,应改用动态脚本作为 error-handler 或在应用层处理。

Q5:apt 版与编译版二进制/服务如何区分?

项apt 版编译版
二进制/usr/sbin/lighttpd/usr/local/lighttpd/sbin/lighttpd
服务名lighttpd.servicelighttpd-local.service(本文命名)
配置/etc/lighttpd/lighttpd.conf/usr/local/lighttpd/etc/lighttpd-local.conf
日志/var/log/lighttpd//usr/local/lighttpd/var/log/

共存原则:80 端口只能被一个实例占用,另一个实例改 server.port;lighttpd -v 打印的版本(1.4.63 vs 1.4.85)可用于快速区分当前跑的是哪套。

九、卸载与清理

方案 A(apt)卸载:

DEBIAN_FRONTEND=noninteractive apt-get purge -y lighttpd

实测回显(尾部):

(Reading database ... 9150 files and directories currently installed.)
Purging configuration files for lighttpd (1.4.63-1ubuntu3.1) ...
removing dangling symlink /etc/lighttpd/conf-enabled/99-unconfigured.conf ...
dpkg: warning: while removing lighttpd, directory '/var/www/html' not empty so not removed
Purging configuration files for lighttpd-mod-openssl (1.4.63-1ubuntu3.1) ...
Purging configuration files for lighttpd-mod-deflate (1.4.63-1ubuntu3.1) ...
DEBIAN_FRONTEND=noninteractive apt-get autoremove -y

实测回显(尾部):

Removing netbase (6.3) ...
Removing perl-modules-5.34 (5.34.0-3ubuntu1.9) ...
Removing spawn-fcgi (1.6.4-2) ...
Processing triggers for libc-bin (2.35-0ubuntu3.15) ...

⚠️ 注意:purge 不清理站点内容——/var/www/html/index.lighttpd.html(占位页)与你在该目录放置的页面会保留,删除站点请自行处理;/var/log/lighttpd/ 旧日志同样保留。

方案 B(编译版)卸载:整个前缀即全部产物,先停服务、撤开机自启,再删目录:

systemctl stop lighttpd-local
systemctl disable lighttpd-local

实测回显(disable 一条):

Removed "/etc/systemd/system/multi-user.target.wants/lighttpd-local.service".
rm -f /etc/systemd/system/lighttpd-local.service && systemctl daemon-reload
rm -rf /usr/local/lighttpd

💡 说明:源码目录 /root/lighttpd-1.4.85/(约 60MB 构建中间产物)如不再需要二次编译,一并删除即可。

十、参考链接

  1. lighttpd 官网下载页(latest.txt 与 sha256sum):https://download.lighttpd.net/lighttpd/releases-1.4.x/
  2. 官方安装/构建说明(meson 构建):https://redmine.lighttpd.net/projects/lighttpd/wiki/InstallFromSource
  3. Ubuntu 包信息:https://packages.ubuntu.com/jammy/lighttpd
  4. systemd 单元与 kill -USR1 优雅重启机制:/lib/systemd/system/lighttpd.service(随包文件,见 4.2)
  5. 同专栏文档:《Lighttpd 介绍与选型指南》、《Lighttpd 1.4.85 配置参数详解》、《Lighttpd 1.4.85 常用 CLI 命令详解》
  6. 本文实测环境:Ubuntu 22.04.5 LTS,lighttpd 1.4.63-1ubuntu3.1 / 1.4.85 源码编译,全部命令实测日期 2026-10-20