标签:lighttpd
为什么要使用lighttpd?
apache不可以吗?
在支持纯静态的对象时,比如图片,文件等 ,
lighttpd速度更快,更理想
至于它和apache的比较,很多文档,大家可以百度一下
本次使用1.4.41版本
官方下载站点:http://www.lighttpd.net/download/
官方给出了安装配置的详细文档
http://redmine.lighttpd.net/projects/lighttpd/wiki/InstallFromSource
前期的简单准备工作
配置防火墙,开启80端口
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #允许80端口通过防火墙
备注:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败,
正确的应该是添加到默认的22端口这条规则的下面
如下所示:
################################ 添加好之后防火墙规则如下所示################################
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
#######################################################################################
/etc/init.d/iptables restart #最后重启防火墙使配置生效
关闭SELINUX
vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq #保存退出
shutdown -r now #重启系统
安装第三方yum源
yum install wget #安装下载工具
yum update #更新yum源
安装nginx
yum remove httpd* php* #删除系统自带的软件包
wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.41.tar.gz
tar -zxvf lighttpd-1.4.41.tar.gz
cd lighttpd-1.4.41
编译:
# ./configure --prefix=/usr/local/lighttpd
# make
# make install
OK!
编译后配置:
以下的doc目录是在解压缩/home/lighttpd-1.4.41/下
也就是当前目录为 /home/lighttpd-1.4.41/
cp -p doc/initscripts/sysconfig.lighttpd /etc/sysconfig/lighttpd
mkdir /etc/lighttpd ##创建配置文件目录
cp doc/config/lighttpd.conf /etc/lighttpd/lighttpd.conf #复制配置文件到配置目录下
cp -R doc/config/conf.d/ doc/config/*.conf doc/config/vhosts.d/ /etc/lighttpd/ #复制配置文件
如果你的Linux是RedHat,那么:
cp doc/initscripts/rc.lighttpd.redhat /etc/init.d/lighttpd ##复制自启动
chmod a+rx /etc/init.d/lighttpd #给可启动的权限
然后修改/etc/init.d/lighttpd,把lighttpd="/usr/sbin/lighttpd"
改为lighttpd="/usr/local/lighttpd/sbin/lighttpd"
此脚本用来控制lighttpd的启动关闭和重起:
# /etc/init.d/lighttpd start
chkconfig lighttpd on ##设置开机自启动
配置lighttpd.conf文件
vim /etc/lighttpd/lighttpd.conf
################################################
var.log_root = "/www/logs" ##错误日志根目录
var.server_root = "/www" ##网站根目录
var.state_dir = "/var/run" ##lighttpd运行目录
var.home_dir = "/www"
var.conf_dir = "/etc/lighttpd" ##配置目录
注意自己的网站目录地址
var.vhosts_dir = server_root + "/vhosts"
var.cache_dir = "/www" ##缓存目录
var.socket_dir = home_dir + "/sockets"
include "modules.conf"
server.port = 80 # 服务监听端口
server.username = "nobody" ##lighttpd的用户(用什么权限来运行lighttpd)
server.groupname = "nobody" ##lighttpd的用户组
server.document-root = server_root + "/htdocs" ##网站存放站点
server.pid-file = state_dir + "/lighttpd.pid" 进程id记录位置
server.errorlog = log_root + "/error.log" # 错误日志位置
include "conf.d/access_log.conf"
include "conf.d/debug.conf"
server.event-handler = "linux-sysepoll"
server.network-backend = "sendfile"
server.max-fds = 2048 ##最大连接数,大流量网站推荐2048
server.stat-cache-engine = "simple"
server.max-connections = 1024
index-file.names += (
"index.xhtml", "index.html", "index.htm", "default.htm", "index.php"
)
url.access-deny = ( "~", ".inc" )
$HTTP["url"] =~ "\.pdf$" {
server.range-requests = "disable"
}
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".scgi" )
include "conf.d/mime.conf"
include "conf.d/dirlisting.conf"
server.follow-symlink = "enable"
server.upload-dirs = ( "/var/tmp" )
include_shell "cat /etc/lighttpd/vhosts.d/*.conf"
###################################################################################
以上是lighttpd.conf 的文件内容
modules.conf 配置文件内容 讲下面行前面的注释#去掉
#################################################################################
server.modules = (
"mod_access",
"mod_rewrite",
include "conf.d/compress.conf"
include "conf.d/fastcgi.conf"
include "conf.d/cgi.conf"
include "conf.d/simple_vhost.conf"
###############################################################################
开设多部虚拟机
##############################################################################
lighttpd虚拟主机配置
$HTTP["host"] == "bbs.xxx.com" {
server.name = "bbs.xxx.com" ##可不用
server.document-root = "/www/vhosts/bbs.xxx.com"
server.errorlog = "/www/vhosts/bbs.xxx.com/error.log"
accesslog.filename = "/www/vhosts/bbs.xxx.com/access.log"
}
##############################################################################
# 针对端口的虚拟主机
$SERVER["socket"] == "192.168.0.1:8000" {
server.document-root = "/var/www/xxx/"
server.errorlog = "/var/log/lighttpd/test-error.log"
accesslog.filename = "/var/log/lighttpd/test-access.log"
}
#############################################################################
配置/etc/lighttpd/conf.d/fastcgi.conf 文件调用php文件
server.modules += ( "mod_fastcgi" )
fastcgi.server = (
".php" => ((
"host" => "127.0.0.1",
"port" => "9000",
#"docroot" => "/www/htdocs"
)))
标签:lighttpd
原文地址:http://lzyaks.blog.51cto.com/1214778/1839755