早上一来,就说要吧apache换成lighttpd 我记得我去年,就提过。竞争对手那时跑的还是apache + squid。 结果,和上级协商不同,就放弃。可能我个人沟通能力有问题。 今天,看到竞争对手换上了lighttpd,领导们说也要换上。汗! 总结些今天对lighhtpd的学习吧, lighttpd 是一个 轻量级 快速的web server 响应速度比apache快,适合跑静态页面,和图片。 使用了 linux-syspoll的 调度当时。比apache 的 select 要快很多吧。 接下来时安装:(演示下,没什么好说,linux 安装三部曲)

./configure \
--prefix=/opt/app/lighttpd/ \
--enable-lfs \
--with-pcre \
--with-zlib \
--without-bzip2 \
--without-openssl \
--with-fam
make && make install

按装就这样吧,解读下 配置文件,呵呵:

server.port                = 80
server.pid-file            = "/var/run/lighttpd.pid"
server.username            = "nobody"
server.groupname           = "nobody"

server.modules              = (
"mod_rewrite",
"mod_redirect",
"mod_access",
"mod_compress",
"mod_ssi",
"mod_expire")

server.document-root        = "/opt/case/"
server.errorlog             = "/dev/null"
index-file.names            = ( "index.html","index.htm")

#性能优化
server.max-worker = 8
server.max-keep-alive-requests = 150
server.max-keep-alive-idle = 10
server.max-read-idle = 30
server.max-write-idle = 30
server.max-fds = 8192
server.max-connections = 4096
server.network-backend = "linux-sendfile"
server.stat-cache-engine = "fam"   # either fam, simple or disabled
server.event-handler = "linux-sysepoll"

mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jar"          =>      "application/x-java-archive",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar",
  # default mime type
  ""              =>      "application/octet-stream",
 )
 server.tag                 = "Microsoft-IIS/6.0"
ssi.extension = ( ".shtml" )
url.access-deny             = ( "~", ".inc" )

$HTTP["url"] =~ "\.pdf$" {
  server.range-requests = "disable"
}


#配置静态页面压缩
compress.cache-dir         = "/tmp/lighttpd/compress/"
compress.filetype          = ("text/plain", "text/html", "text/javascript","text/css")

#配置 expire
$HTTP["url"] =~ "\.(jp[e]?g|bmp|png|gif|css)$" {
expire.url = ( "" => "access 12 months" )
}
$HTTP["url"] =~ "(htm[l]?|js|css)?$" {
expire.url = ( "" => "access 10 days" )
}

################ vhost config ############################
$HTTP["host"] =~ "linux.org" {
server.document-root = "/opt/case/www.linux.org/"
server.name = www.linux.org
server.follow-symlink = "enable"
}

#url 重定向
$HTTP["host"] =~ "(?:www[\.]?)?linux\.com" {
url.redirect = ( "^/(.*)" => http://www.linux.org/ )
}