linux下安裝lighttpd配置詳解

爲什麼要使用lighttpd? 
     apache不可以嗎? 
     在支持純靜態的對象時,比如圖片,文件等 , 
     lighttpd速度更快,更理想 
     至於它和apache的比較,很多文檔,大家可以百度一下

本次使用1.4.41版本

官方網點:http://www.lighttpd.net

官方下載站點:http://www.lighttpd.net/download/

wKiom1e0gh6SOWBWAADBShNC00o664.jpg-wh_50

官方給出了安裝配置的詳細文檔

http://redmine.lighttpd.net/projects/lighttpd/wiki/InstallFromSource

wKioL1e0hgbChpknAADXOFjyvy8723.jpg-wh_50


前期的簡單準備工作

配置防火牆,開啓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

wKiom1e0hITwvUv6AAG288W9WCI386.jpg-wh_50

tar -zxvf lighttpd-1.4.41.tar.gz

wKioL1e0hM_g2LLFAAFgwOH84Iw590.jpg-wh_50



cd lighttpd-1.4.41

編譯:

  1. # ./configure --prefix=/usr/local/lighttpd

  2. # make

  3. # make install

  4. 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"

  )))



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章