Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

CentOS 编译安装 Lighttpd 1.4.x 完整步骤与配置部署

編輯:關於 Linux

Lighttpd(Lighty)是轻量级高性能 Web 服务器,适合静态资源、嵌入式设备或低配 VPS。CentOS 官方源版本较旧,本文记录从源码编译安装 Lighttpd 1.4.19、依赖处理、Systemd 服务注册与基础配置全过程。

一、安装编译依赖

sudo yum install gcc make pcre-devel zlib-devel openssl-devel

二、下载、编译、安装

wget https://www.lighttpd.net/download/lighttpd-1.4.19.tar.gz
tar zxvf lighttpd-1.4.19.tar.gz
cd lighttpd-1.4.19
./configure --prefix=/usr/local/lighttpd --with-pcre
make
sudo make install

三、部署配置文件与启动脚本

# 复制示例配置
sudo cp doc/lighttpd.conf /usr/local/lighttpd/conf/
sudo mkdir -p /etc/lighttpd
sudo ln -s /usr/local/lighttpd/conf/lighttpd.conf /etc/lighttpd/

# 复制 Systemd 服务文件(RedHat 系列)
sudo cp doc/rc.lighttpd.RedHat /etc/init.d/lighttpd
sudo chmod +x /etc/init.d/lighttpd

# 修正启动脚本中的二进制路径
sudo sed -i 's|^prog="lighttpd"|lighttpd="/usr/local/sbin/lighttpd"|' /etc/init.d/lighttpd
# 注:make install 后二进制通常在 /usr/local/sbin/lighttpd

四、创建日志目录与网站根目录

sudo mkdir -p /var/log/lighttpd
sudo touch /var/log/lighttpd/access.log /var/log/lighttpd/error.log
sudo chown -R lighttpd:lighttpd /var/log/lighttpd

# 默认网站根目录
sudo mkdir -p /srv/www/htdocs
sudo chown -R lighttpd:lighttpd /srv/www/htdocs

五、编辑 lighttpd.conf 关键段

server.modules = (
    "mod_access", "mod_alias", "mod_compress", "mod_redirect",
    "mod_accesslog"
)

server.document-root = "/srv/www/htdocs/"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
server.errorlog = "/var/log/lighttpd/error.log"
accesslog.filename = "/var/log/lighttpd/access.log"
server.port = 80
server.username = "lighttpd"
server.groupname = "lighttpd"
index-file.names = ( "index.html", "index.php" )

# 启用压缩
compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = ( "text/plain", "text/html", "application/javascript", "text/css", "text/xml" )

六、启动并设置开机自启

sudo service lighttpd start
sudo chkconfig lighttpd on
# 或 systemd
sudo systemctl enable --now lighttpd

Lighttpd 编译安装示意图

完成编译安装与配置,Lighttpd 即可作为高性能静态 Web 服务器运行。如需 PHP 支持,配置 mod_fastcgi 连接 php-fpm 即可。

Copyright © Windows教程網 All Rights Reserved