Lighttpd那些事儿

来源:互联网 发布:javascript输出表格 编辑:程序博客网 时间:2024/04/30 19:12

 

 

1.lighttpd简单聊聊

Lighttpd,正如它的名字所示,是一个轻量级的web服务器,除了轻量之外,它还拥有安全性高、速度快、标准化配置等等特性,另外它是开源的, 在BSD协议下发行。

 

Lighttpd的一些特性:

 

FastCGI 

COMET—— HTTP长链接技术

Async IO——sendfile

 

2.简单配置

配置语法:http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:Configuration

获取环境变量的值:env.XXX

定义变量 var.t1 = "test",使用变量 t1

 

配置例子:http://redmine.lighttpd.net/projects/lighttpd/wiki/TutorialConfiguration

------------------------------------------------------------------------------

#root目录设置

server.document-root = "/var/www/servers/www.example.org/pages/" 

 

# ip, port设置

server.port = 80

#server.bind = "127.0.0.1"

 

用户,组设置

server.username = "www" 

server.groupname = "www" 

 

mimetype.assign = (

  ".html" => "text/html", 

  ".txt" => "text/plain",

  ".jpg" => "image/jpeg",

  ".png" => "image/png" 

)

 

static-file.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc" )

index-file.names = ( "index.html" )

# url映射设置

$HTTP["host"] == "www2.example.org" {

  server.document-root = "/var/www/servers/www2.example.org/pages/" 

  $HTTP["url"] =~ "^/download/" {

    dir-listing.activate = "enable" 

  }

}

 

------------------------------------------------------------------------------

配置例子文件下载:http://redmine.lighttpd.net/repositories/entry/lighttpd/branches/lighttpd-1.4.x/doc/lighttpd.conf

 

测试lighttpd.conf配置脚本是否正确:lighttpd -t -f lighttpd.conf

 

3.访问日志配置

http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModAccessLog

server.errorlog             = "tmp/logs/lighttpd/error.log/"

 

# access log

accesslog.format = "%h %V %u %t /"%r/" %>s %b /"%{Referer}i/" /"%{User-Agent}i/""

accesslog.filename = "|/usr/sbin/cronolog /tmp/logs/lighttpd/%Y/%m/%d.log"

# cronolog是需要另外装的 http://cronolog.org/ 这样设置之后,每天一个日志文件,便于分析,且日志文件不会无限增长。

 

4.系统相关配置优化

http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:Performance

禁用keep-alive: server.max-keep-alive-requests = 0

 

修改文件描述符限制(要root帐户):server.max-fds = 2048

Linux下默认的文件描述符(文件描述符简单来说就是一个进程打开文件的时的特定表示)数是1024,意味着一个进程同时最多只能打开1024个文件。

ulimit -n 可以看到当前系统的文件描述符数量

ulimit -a 可以看到系统的其他一些限制参数

直接修改文件描述符:

ulimit -n 2048 只对当前shell有效

在/etc/security/limits.conf中增加* - nofile 65535 重新登录

 

设置缓存:server.stat-cache-engine = "fam"   # either fam, simple or disabled

 

sock链接time_out居多,可以使用命令netstat -n|awk '/^tcp/{++S[$NF]} END {for(a in S) print a,S[a]}' 查看当前链接情况,据说这个语句是从新浪的一位技术牛人手里流出来的,http://duckweeds.blog.sohu.com/97159783.html

http://higkoo.blog.sohu.com/107616563.html

TIME_OUT超多时,导致服务器无法响应新的请求,对于TIME_OUT超多可以做如下处理:

  # These ensure that TIME_WAIT ports either get reused or closed fast.

  net.ipv4.tcp_fin_timeout = 1

  net.ipv4.tcp_tw_recycle = 1

  # TCP memory

  net.core.rmem_max = 16777216

  net.core.rmem_default = 16777216

  net.core.netdev_max_backlog = 262144

  net.core.somaxconn = 262144

 

  net.ipv4.tcp_syncookies = 1

  net.ipv4.tcp_max_orphans = 262144

  net.ipv4.tcp_max_syn_backlog = 262144

  net.ipv4.tcp_synack_retries = 2

  net.ipv4.tcp_syn_retries = 2

 

  # you shouldn't be using conntrack on a heavily loaded server anyway, but these are 

  # suitably high for our uses, insuring that if conntrack gets turned on, the box doesn't die

  net.ipv4.netfilter.ip_conntrack_max = 1048576

  net.nf_conntrack_max = 1048576

 

5.其他模块的配置

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

 

原创粉丝点击