m2014-architecture-imgserver->配置lighttpd mod_mem_cache 模块做静态资源服务器
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。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 模块做静态资源服务器的更多相关文章
- 初始nginx(启动运行) 使用nginx做一个简单的静态资源服务器
第一次接触nginx的时候,那时候公司还是用的一些不知名的小技术,后来公司发展问题,重新招了人,然后接触到nginx,公司 使用nginx用来做代理服务器,所有请求 都先经过nginx服务器,然后交由 ...
- Spring Mvc Web 配置拦截规则与访问静态资源 (三)
拦截规则配置 1. *.do <!-- Processes application requests --> <servlet> <servlet-name>app ...
- 动态script标签同步加载 ps:无打包编译,静态实现静态资源入口动态配置,无编译打包静态资源添加版本号
/**功能:创建动态标签加载css ,js文件,重点是js文件,利用onloading加递归实现动态标签的同步加载用法:在html文件body底部script内部声明并调用下列函数,obj中写要加载的 ...
- nginx静态资源服务器简单配置
有时候我们可以把服务器的一些文件放在固定目录以便下载,比如image,css,js等.就可以使用nginx转发静态资源. 参考链接:https://blog.csdn.net/name_is_wl/a ...
- Nginx配置实例-动静分离实例:搭建静态资源服务器
场景 Nginx入门简介和反向代理.负载均衡.动静分离理解: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/102790862 U ...
- SpringBoot 配置静态资源映射
SpringBoot 配置静态资源映射 (嵌入式servlet容器)先决知识 request.getSession().getServletContext().getRealPath("/& ...
- 关于linux下部署JavaWeb项目,nginx负责静态资源访问,tomcat负责处理动态请求的nginx配置
1.项目的运行环境 linux版本 [root@localhost ~]# cat /proc/version Linux version -.el6.x86_64 (mockbuild@x86-.b ...
- nginx 配置静态资源路径(url不同于static path)
目的 用nginx做静态资源代理可以减少请求对后台服务器的压力,使响应更加迅速. 配置 情景一 url : 127.0.0.1:8000/images ...
- 【spring boot】7.静态资源和拦截器处理 以及继承WebMvcConfigurerAdapter类进行更多自定义配置
开头是鸡蛋,后面全靠编!!! ======================================================== 1.默认静态资源映射路径以及优先顺序 Spring B ...
随机推荐
- c++重载前置++和--
C语言中,前置和后置++,--都不能作为左值,而在c++中,前置的++和--可以作为左值,从下面的重载运算符中也可以看出,它们返回的是引用,我不知道为什么这里和c语言中不同,但c++类似的提升还有三目 ...
- pyqt重写键盘事件+获取信号发送对象
# _*_ coding:utf-8 _*_ import sys from PyQt4 import QtGui,QtCore class Example(QtGui.QMainWindow): d ...
- mysql 5.7.12----bin/mysqld --initialize --user=mysql出错
我最近在安装mysql 5.7.12,本来之前安装mysql 5.7.11时用命令 bin/mysqld --initialize --user=mysql 可以很好的初始化,但是用在5.7.12版本 ...
- 指针的引用(*&)与指针的指针(**)
指针的引用(*&)与指针的指针(**) 在下列函数声明中,为什么要同时使用*和&符号?以及什么场合使用这种声明方式? void func1( MYCLASS *&pBuildi ...
- 浅谈WebService的调用<转>
0.前言 前段时间,公司和电信有个合作,产品对接电信的某个平台,使用了WebService接口的调用,实现了业务受理以及单点登录.终于使用到了WebService,楼主还是比较兴奋的,目前功能已经上线 ...
- Android——滚动视图(ScrollView)图片视图(ImageView)、状态开关按钮(ToggleButton)、时钟
xml <?xml version="1.0" encoding="utf-8"?> <!--滚动视图--> <ScrollVie ...
- gdb常用
调试信息条件:-g或-gdbgcc -g -o test test.cgcc -ggdb3 -o test test.cggdb3告诉gcc,使用gdb的扩展产生调试符号.其中“3”表示使用的是第三 ...
- mysql的navicat执行存储过程
---------------------------存储过程------------------------ BEGIN #Routine body goes here...SELECT p_in; ...
- gulp配置安装使用
安装 $ npm install gulp -g //全局安装gulp,让你可存取gulp的CLI //接着需要在本地端的专案进行安装,cd到专案根目录,执行 $ npm install gulp - ...
- 关于用Spine制作骨骼动画的步骤
步骤: 1.打开spine. 2.新建一个空项目. 3.点右边Tree下的Images模块,导入在自己的切片素材和原整图. 4.把原整图拖到场景中,点右下角Color改变原图的颜色,方便后面对照. 5 ...