配置lighttpd mod_mem_cache 模块做静态资源服务器

简介:

一   lighttpd 简介 

Lighttpd 是一个德国人领导的开源Web服务器软件,其根本的目的是提供一个专门针对高性能网站,安全、快速、兼容性好并且灵活的web server环境。具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点。

 
 
二 下载lighttpd,并编译安装lighttpd
     wget http://lighttpd-improved.googlecode.com/files/lighttpd-1.4.26.modcache.v.1.8.3-2.tar.gz
     #tar  xf  lighttpd-1.4.26.modcache.v.1.8.3-2.tar.gz
     #cd   lighttpd-1.4.26
     # ./configure --prefix=/usr/local/lighttpd --with-zlib --with-bzip2 --with-memcache
     #make && make install
     #cd  doc
     #cp   rc.lighttpd.redhat    /etc/init.d/lighttpd
     #cp sysconfig.lighttpd  /etc/sysconfig/lighttpd
     #vim /etc/sysconfig/lighttpd  
      修改如下
       LIGHTTPD_CONF_PATH=/usr/local/lighttpd/conf/lighttpd.conf
     #
     #chmod 700   /etc/init.d/lighttpd
     #vim 修改如下选项
       config: /usr/local/lighttpd/conf/lighttpd.conf
       config: /etc/sysconfig/lighttpd
       pidfile: /var/run/lighttpd.pid
       LIGHTTPD_CONF_PATH="/usr/local/lighttpd/conf/lighttpd.conf"
       lighttpd="/usr/local/lighttpd/sbin/lighttpd"
 
     #mkdir /usr/local/lighttpd/{cache,logs,conf,htdocs}
     #cp  lighttpd.conf /usr/local/lighttpd/conf
 
三 配置详解
  #cd  /usr/local/lighttpd/conf
  # cat lighttpd.conf
  # lighttpd configuration file
  #
  # use it as a base for lighttpd 1.0.0 and above
  #
  # $Id: lighttpd.conf,v 1.7 2004/11/03 22:26:05 weigon Exp $
  ############ Options you really have to take care of ####################  
  ## modules to load
  # at least mod_access and mod_accesslog should be loaded
  # all other module should only be loaded if really neccesary
  # - saves some time
  # - saves memory
  #lighttpd 加载的模块
  server.modules              = (
                                "mod_rewrite",
                                "mod_redirect",
                                "mod_access",
                                "mod_expire",
                                "mod_mem_compress",
                                "mod_compress",                         
                                "mod_mem_cache",
                                "mod_cache",
                                "mod_dirlisting",
                                "mod_status",,
                                "mod_fastcgi",
                                "mod_proxy",                         
                                "mod_usertrack",
                                "mod_accesslog" )
 
  ## a static document-root, for virtual-hosting take look at the
  ## server.virtual-* options
  server.document-root        = "/usr/local/lighttpd/htdocs/"  
  ## where to send error-messages to
  server.errorlog             = "/usr/local/lighttpd/logs/error.log"    
  # files to check for if .../ is requested
  index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm" )
  ## set the event-handler (read the performance section in the manual)
  # server.event-handler = "freebsd-kqueue" # needed on OS X  
  # mimetype mapping
  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",
  )  
  # Use the "Content-Type" extended attribute to obtain mime type if possible
  #mimetype.use-xattr        = "enable"
 
  ## send a different Server: header
  ## be nice and keep it at lighttpd
  # server.tag                 = "lighttpd"
  #### accesslog module
  #accesslog.filename          = "/usr/local/lighttpd/log/access.log"
  #设置日志切割,当然需要安装cronlog 工具
  accesslog.filename = "|/usr/local/cronolog/sbin/cronolog    /usr/local/lighttpd/logs/%w/access.log"
  ## deny access the file-extensions
  #
  # ~    is for backupfiles from vi, emacs, joe, ...
  # .inc is often used for code includes which should in general not be part
  #      of the document-root
  url.access-deny             = ( "~", ".inc" )
  $HTTP["url"] =~ "\.pdf$" {
    server.range-requests = "disable"
  }
  ##
  # which extensions should not be handle via static-file transfer
  #
  # .php, .pl, .fcgi are most often handled by mod_fastcgi or mod_cgi
   static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
  ######### Options that are good to be but not neccesary to be changed #######
   ## bind to port (default: 80)
  #server.port                = 81
  ## bind to localhost (default: all interfaces)
  #server.bind                = "127.0.0.1"  
  ## virtual directory listings 关闭目录浏览
  dir-listing.activate       = "disable"
  #或者  server.dir-listing = "disable"
 
  ## select encoding for directory listings 设置字符编码
   dir-listing.encoding        = "utf-8"

   #### compress module 压缩模块的设置
   #压缩cache 存储路径
   compress.cache-dir         = "/usr/local/lighttpd/cache/"
   #压缩 文件类型
   compress.filetype          = ("text/html;charset=utf-8","text/plain;charset=utf-8","text/css", "text/javascript", "text/xml","application/x-java-archive")

  #### status module 设置查看lighttpd 状态
  #设置允许查看lighttpd 状态的主机
  $HTTP["remoteip"] == "192.168.1.0/24" {
  status.status-url = "/server-status"
  status.config-url = "/server-config"
  status.statistics-url = "/cache-status"
  }  
  #### expire module
  #expire.url                 = ( "/buggy/" => "access 2 hours", "/asdhas/" => "access plus 1 seconds 2 minutes")
 
   #设置文件类型,在浏览器中缓存的时间
  $HTTP["url"] =~ "\.(jpg|gif|bmp|jpeg)$" {
       expire.url = ( "" => "access 5 minutes")
  }
 
  $HTTP["url"] =~ "\.(html|htm|shtml)$" {
      expire.url = ( "" => "access 5 minutes")
  }
 
  $HTTP["url"] =~ "\.(png)$" {
      expire.url = ( "" => "access 5 minutes")
   }
 
  $HTTP["url"] =~ "\.(css|js|xml)$" {
     expire.url = ( "" => "access 5 minutes")
  }
 
  $HTTP["url"] =~ "\.(ico)$" {
       expire.url = ( "" => "access 262800 minutes")
  }
 
  #memcache for static web page server  设置 开启cache 
  cache.support-queries = "enable" #ignore '?' in url
  cache.dynamic-mode = "enable"
  #设置cache 存储的路径
   cache.bases = ("/usr/local/lighttpd/cache") #write cached files in      /usr/local/lighttpd/cache directory
   #设置不同的文件类型的cache 刷新的时间
   cache.refresh-pattern = (
  #         "\.(?i)(flv)$" => "0 fetchall-for-range-request flv-streaming", # to   work with mod_flv_streaming for flv files
        "\.(?i)(js|css|xml)$" => "10080", # update js/css/xml every 1 week and on refresh requests
        "\.(?i)(htm|html|shtml)$" => "5", # update html/htm/shtml every 5 minutes and on refresh requests
        "\.(?i)(jpg|bmp|jpeg|gif|png)$" => "10080", # update graphics files every 1 week
  #        "\.(?i)(png)$" => "5", #update png every 5 minutes and on refresh requests
        "\.(?i)(ico)$" => "262800", #update ico every 6 months and on refresh requests
  #        "\.(?i)(rar|zip|wmv|avi|mp3|ape|rm|mpeg|mpg|wma|asf|rmvb|flv)$" => "0 fetchall-for-range-request", # cache media file forever
   #        "." => "30 update-on-refresh" # default to update every 30 minutes and on refresh requests
)
 
  #purge cache  设置允许清除cache  的主机
  cache.purge-host = "192.168.1.0/24"
 
   #it's important to enable proxy.worked-with-mod-cache or mod_proxy will not   cooperate with modcache
   #enable or disable mod_mem_cache  设置 开启基于mod_mem_cache 模块
   mem-cache.enable = "enable"
 
   #content-type arrays which want to put into memory 设置允许在mem_cache 存储的类型
   mem-cache.filetypes = ("application/x-javascript","image/gif","image/jpg","image/jpeg","image/png","text/css","text/html","text/javascript","text/plain")
 
   #maxium memory in Mbytes mod_mem_cache can use 设置mem-cache  允许使用的最大内存
   mem-cache.max-memory = "1024"
 
   #maxium file size in Kbytes of single file to cache in memory  设置在内存中存储的最大文件大小
   mem-cache.max-file-size = "1024"
 
   #number of cached memory items to remove when used memory reached maxmemory by LRU algorthim #设置当使用的内存达到最大值时,通过LRU 算法删除的内存cache 的大小
   mem-cache.lru-remove-count = "500"
 
   #memory cache`s expire time in minutes.Default: 0 (means to check file update for every request) 设置memory cache 的过期时间
   mem-cache.expire-time = "1440"
 
   #adjusts slru threshold (against hit counter)
   mem-cache.slru-thresold = "0"
 
     #stat() 这样的系统调用,开销也是相当明显的。缓存能够节约时间和环境切换次数(context switches),此项有三个选项:fam、simple(缓存1秒内的stat())和disabled。一般我们较多使用前两项
   server.stat-cache-engine = "simple"
 
   #usertrack.cookie-domain
   #usertrack.cookie-domain = ".example.com"
 
   #sets the maximum duration in seconds of the cookie.if not specified it will not add a 'max-age' to the cookie,meaning it will not expire
#usertrack.cookie-max-age = "60"
 
   #this option allows the setting of the name of the cookie.the default is 'TRACKID'.currently it only allow a-z
   #usertrack.cookie-name = "trackid"
 
   # set lighttpd open file num 设置允许的最大文件描述符个数。lighttpd是单线程的服务器,其最大的资源限制就是文件描述符的数量,默认为1024。对于高负荷的站点,需要增加该值,对于较为繁忙的服务器设置为2048较好。修改该设置需要root权限。
   server.max-fds = "65535"
 
   #设置lighttpd 最大连接数
   #Provides fine tuning for request handling.max-connections == max-fds/2 (maybe /3).As in, if you want to support 2048 concurrent connections, 
you may also want to set server.max-fds = 4096 (or 6144).Why more file handles than connections? The other file handles are used for fastcgi and/or files.
   server.max-connections = "32767"
 
   #http Keep-Alive 一般来说,一个系统能够打开的文件个数是有限制的(文件描述符限制)。常连接占用文件描述符,对非并发的访问没有什么意义
默认情况下lighttpd 做多可以同时承受30 s的长连接,每个连接最多请求128 个文件
   #server.max-keep-alive-requests = 128
   #server.max-keep-alive-idle =30
   #the maximum of keep alive requests enable or disable 
   server.max-keep-alive-requests = "1000"  #"0" represent disable
 
   #sets the linux system support for transaction processing,Lighttpd 
   #大量使用了 sendfile() 这样一个高效的系统调用。减少了从应用程序到网卡间的距离。(同时也减少了Lighttpd对cpu的占用,这部分占用转嫁到内核身上了)
   server.event-handler = "linux-sysepoll"
 
   #such a highly active system call which a lot of sendfile() used by      lighttpd,reduce the distance from application to ethernet
   server.network-backend = "linux-sendfile"
   #禁止etags 功能
   static-file.etags = "disable"
   #配置lighttpd 多进程,一般和CPU 个数相同
   server.max-worker=4
 
    注:
       官方lighttpd 优化方案:http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_Performance
                          http://www.unixvip.com/app/lighttpd/616.html









本文转自 freehat08 51CTO博客,原文链接:http://blog.51cto.com/freehat/989171,如需转载请自行联系原作者
目录
相关文章
|
7天前
|
消息中间件 安全 Unix
SSH配置多台服务器之间的免密登陆以及登陆别名
SSH配置多台服务器之间的免密登陆以及登陆别名
18 1
|
22天前
|
弹性计算
2024年阿里云服务器不同实例规格与配置实时优惠价格整理与分享
2024年阿里云服务器的优惠价格新鲜出炉,有特惠云服务器也有普通优惠价格,本文为大家整理汇总了2024年阿里云服务器的优惠价格,包含特惠云服务器和其他配置云服务器的优惠价格。以便大家了解自己想购买的云服务器选择不同实例规格和带宽情况下的价格,仅供参考。
2024年阿里云服务器不同实例规格与配置实时优惠价格整理与分享
|
4天前
|
存储 弹性计算 安全
阿里云服务器2核2G、2核4G配置最新租用收费标准及活动价格参考
2核2G、2核4G配置是很多个人和企业建站以及部署中小型的web应用等场景时首选的云服务器配置,这些配置的租用价格也是用户非常关心的问题,本文为大家整理汇总了2024年阿里云服务器2核2G、2核4G配置不同实例规格及地域之间的收费标准,同时整理了这些配置最新活动价格,以供大家参考和选择。
阿里云服务器2核2G、2核4G配置最新租用收费标准及活动价格参考
|
7天前
|
域名解析 网络协议 应用服务中间件
阿里云服务器配置免费https服务
阿里云服务器配置免费https服务
|
10天前
|
数据采集
robots.txt配置 减小服务器压力
robots.txt配置 减小服务器压力
13 0
|
21天前
|
网络协议 Linux 网络安全
Linux服务器DNS服务器配置实现bind的正向解释和反向解释
Linux服务器DNS服务器配置实现bind的正向解释和反向解释
17 0
|
22天前
|
弹性计算 网络安全 虚拟化
ECS数据问题之升级配置预防数据丢失如何解决
ECS(Elastic Compute Service,弹性计算服务)是云计算服务提供商提供的一种基础云服务,允许用户在云端获取和配置虚拟服务器。以下是ECS服务使用中的一些常见问题及其解答的合集:
|
23天前
|
弹性计算 Kubernetes 安全
ECS选型推荐配置
在构建Kubernetes集群时,应避免使用过多小规格ECS,因它们可能带来网络限制、容量不足和资源碎片化问题。采用大规格ECS能提升网络性能,优化镜像拉取效率。选择Master节点时,要考虑集群规模,生产环境建议选择较高规格。Worker节点推荐使用CPU≥4核、内存≥8GiB的ECS,根据集群总核数和容错率来决定节点数量。当规模达1000核,可选用裸金属神龙服务器,它提供超强网络、零计算抖动和安全性能,适合大促等需快速扩展的场景。
25 1
|
27天前
|
弹性计算 固态存储 调度
2024年阿里云服务器配置选择指南,新手整理
阿里云服务器配置选择指南:个人用户推荐轻量应用服务器或ECS通用算力型u1,适合小型网站和轻量应用。企业用户应选择企业级独享型如ECS计算型c7、通用型g7,保证高性能计算需求。配置选择要考虑CPU内存比例、公网带宽和系统盘。轻量服务器提供2核2G3M和2核4G4M选项,ECS实例则有多种规格以适应不同业务场景。公网带宽建议至少5M,系统盘可选高效云盘、SSD或ESSD。详细信息见[阿里云服务器产品页](https://www.aliyun.com/product/ecs)。
64 3
|
28天前
|
安全 网络安全 数据安全/隐私保护
如何配置常用邮箱服务器_云·企业官网 | 常用邮箱配置邮件服务器
本文介绍了邮件服务器的作用,如接收用户留言和表单通知,并提供阿里云企业邮箱、QQ邮箱、腾讯企业邮箱、163邮箱和谷歌邮箱的配置步骤。建议根据服务器所在地选择相应邮箱服务。配置涉及开启SMTP/POP3服务、获取授权码或应用密码,并在网站后台填写邮件服务器地址、SSL设置、账号和端口等信息。
48 0

热门文章

最新文章