Lighttpd 本地开发指南
轻量级 Web 服务器 Lighttpd 在 localhost 上的安装、默认端口与静态/PHP 站点配置。
Lighttpd(读作 “lighty”)是轻量、低内存占用的 Web 服务器,适合嵌入式设备与资源受限环境,也可用于本地静态站点或 PHP 开发。
默认 localhost 访问
| 用途 | 地址 |
|---|---|
| 默认站点 | http://localhost |
| 自定义端口 | http://localhost:8080 |
默认监听 80 端口,在 lighttpd.conf 中通过 server.port 修改。
安装
- Linux:
sudo apt install lighttpd - macOS:
brew install lighttpd
网站根目录
配置文件通常在 /etc/lighttpd/lighttpd.conf(Linux)或 Homebrew 前缀目录下。
关键配置:
server.document-root = "/var/www/html"
index-file.names = ("index.html", "index.php")启用 PHP(可选)
安装 lighttpd-mod-fastcgi 并配置 FastCGI 指向 PHP-CGI,即可在 localhost 运行 PHP。
常用命令
sudo lighttpd -t -f /etc/lighttpd/lighttpd.conf # 测试配置
sudo systemctl start lighttpd
sudo systemctl reload lighttpd常见问题
403 / 404
检查 document-root 路径与文件权限。
与 Apache/Nginx 端口冲突
修改 server.port = 8080,使用 **http://localhost:8080**。
小结
Lighttpd 占用资源少,适合轻量本地站点。配置 document-root 后通过 http://localhost 访问。