原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://freehat.blog.51cto.com/1239536/989171

一  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

本文出自 “Frank” 博客,请务必保留此出处http://freehat.blog.51cto.com/1239536/989171

m2014-architecture-imgserver->配置lighttpd mod_mem_cache 模块做静态资源服务器的更多相关文章

  1. 初始nginx(启动运行) 使用nginx做一个简单的静态资源服务器

    第一次接触nginx的时候,那时候公司还是用的一些不知名的小技术,后来公司发展问题,重新招了人,然后接触到nginx,公司 使用nginx用来做代理服务器,所有请求 都先经过nginx服务器,然后交由 ...

  2. Spring Mvc Web 配置拦截规则与访问静态资源 (三)

    拦截规则配置 1. *.do <!-- Processes application requests --> <servlet> <servlet-name>app ...

  3. 动态script标签同步加载 ps:无打包编译,静态实现静态资源入口动态配置,无编译打包静态资源添加版本号

    /**功能:创建动态标签加载css ,js文件,重点是js文件,利用onloading加递归实现动态标签的同步加载用法:在html文件body底部script内部声明并调用下列函数,obj中写要加载的 ...

  4. nginx静态资源服务器简单配置

    有时候我们可以把服务器的一些文件放在固定目录以便下载,比如image,css,js等.就可以使用nginx转发静态资源. 参考链接:https://blog.csdn.net/name_is_wl/a ...

  5. Nginx配置实例-动静分离实例:搭建静态资源服务器

    场景 Nginx入门简介和反向代理.负载均衡.动静分离理解: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/102790862 U ...

  6. SpringBoot 配置静态资源映射

    SpringBoot 配置静态资源映射 (嵌入式servlet容器)先决知识 request.getSession().getServletContext().getRealPath("/& ...

  7. 关于linux下部署JavaWeb项目,nginx负责静态资源访问,tomcat负责处理动态请求的nginx配置

    1.项目的运行环境 linux版本 [root@localhost ~]# cat /proc/version Linux version -.el6.x86_64 (mockbuild@x86-.b ...

  8. nginx 配置静态资源路径(url不同于static path)

    目的         用nginx做静态资源代理可以减少请求对后台服务器的压力,使响应更加迅速. 配置        情景一           url : 127.0.0.1:8000/images ...

  9. 【spring boot】7.静态资源和拦截器处理 以及继承WebMvcConfigurerAdapter类进行更多自定义配置

    开头是鸡蛋,后面全靠编!!! ========================================================  1.默认静态资源映射路径以及优先顺序 Spring B ...

随机推荐

  1. 【C#】用List做动态数组

    需求:有时候我们需要一个动态数组,如拼接URL的时候,希望string[]能够动态添加数据. 这时可以使用List集合,List集合可以动态添加元素.最后使用时用List.toArray()方法转成s ...

  2. WIFEXITED/WEXITSTATUS/WIFSIGNALED

    WIFEXITED/WEXITSTATUS/WIFSIGNALED If the exit status value (*note Program Termination::) of the chil ...

  3. Hive中order by,sort by,distribute by,cluster by的区别

    一:order by order by会对输入做全局排序,因此只有一个Reducer(多个Reducer无法保证全局有序),然而只有一个Reducer,会导致当输入规模较大时,消耗较长的计算时间.关于 ...

  4. 使用DroneKit控制无人机

    DroneKit-Python是一个用于控制无人机的Python库.DroneKit提供了用于控制无人机的API,其代码独立于飞控,单独运行在机载电脑(Companion Computer)或其他设备 ...

  5. StarRTC , AndroidThings , 树莓派小车,公网环境,视频遥控(三)手机端

    原文地址:http://blog.starrtc.com/?p=111 这篇来介绍一下整个项目的手机端部分.在上一篇里我们已经将sdk导入到项目中了,下边直接用即可. 1 登录StarRTC的服务跟小 ...

  6. Git服务器搭建全过程分步详解

    GitHub是一个免费托管开源代码的Git服务器,如果我们不想公开项目的源代码,又不想付费使用,那么我们可以自己搭建一台Git服务器. 下面我们就看看,如何在Ubuntu上搭建Git服务器.我们使用V ...

  7. 05 Oracle process

    本章提要----------------------------------------------所有的 process 都是在 PGA 内(memory)server process: 与 cli ...

  8. Framework 7 之 给Picker Modal 添加半透明背景

    官网的效果图如下: 效果图如下: 我们需要在显示下面浮层的时候显示后面的半透明背景,Framework 7 里面默认有个半透明背景,如下图: 解决方案: 1.在</body>标签之前添加& ...

  9. in 型子查询引出的陷阱

    题: 在ecshop商城表中,查询6号栏目的商品, (注,6号是一个大栏目) 最直观的: mysql> select goods_id,cat_id,goods_name from goods ...

  10. 【jQueryEasyUI总结】

    API: EASYUI 实例项目(重要): 社区easyui 论坛: http://bbs.jeasyuicn.com API地址:http://www.jeasyuicn.com/api SSH演示 ...