一、简介
Lighttpd是一个具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点。lighttpd是众多OpenSource轻量级的web server中较为优秀的一个。支持FastCGI, CGI, Auth, 输出压缩(output compress), URL重写, Alias等重要功能。
二、安装与简单配置
lighttpd安装与配置
首先安装epel源,如果已经安装,忽略。
yun install epel-release
yum安装lighttpd
yum install lighttpd lighttpd-fastcgi
三、配置和简单的测试
1. vim /etc/lighttpd/lighttpd.conf
2. 找到server.use-ipv6 = "enable",将”enbale“改为”disable”
3. /etc/init.d/lighttpd start
4. 添加server.document-root = server_root + "/lighttpd"
5. 执行 “wget -q -O - http://localhost” 观察访问是否正常
四、PHP安装与配置
安装php
yum install php-cli
配置php与lighttpd
1. vim /etc/php.d/lighttpd.ini
找到cgi.fix_pathinfo,将其值置为1,结果为:”cgi.fix_pathinfo=1”
2. vim /etc/lighttpd/modules.conf
找到include "conf.d/fastcgi.conf",将其前面的注释删除。
3. vim /etc/lighttpd/conf.d/fastcgi.conf
找到php的配置,做如下更改,主要更改了socket和bin-path两个参数的值
fastcgi.server = ( ".php" =>
( "php-local" =>
(
"socket" => "/tmp/php-fastcgi-1.socket",
"bin-path" => "/usr/bin/php-cgi",
"max-procs" => 1,
"broken-scriptfilename" => "enable",
)
),
4. 创建文件/var/www/lighttpd/index.php,写入如下内容
5. 重启lighttpd, 然后访问http://localhost/index.php,查看输出是否正确
六、MySQL安装和配置
安装MySQL和php的MySQL依赖
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mcrypt
重启lighttpd以后,访问http://localhost/index.php,查看是否已经有MySQL支持。
七、常见错误解决方法:
如果发现一句这样的提示:
warning: please use server.use-ipv6 only for hostnames, not without server.bind / empty address; your config will break if the kernel default for IPV6_V6ONLY changes
请修改/etc/lighttpd/lighttpd.conf:
找到server.use-ipv6 = "enable",默认为enable,改为disable
如果发现一句这样的提示:
can’t have more connections than fds/2: 1024 1024
请修改/etc/lighttpd/lighttpd.conf:
找到#server.max-fds = 2048,去掉前面的#号后重启Lighttpd
如果发现一句这样的提示:
Starting lighttpd: 2016-06-04 14:30:10: (server.c.756) couldn't set 'max filedescriptors' Permission denied
禁用SELinux
八、Lighttpd记录真实IP
vim /etc/lighttpd/conf.d/access_log.conf // 添加
accesslog.format = "%h:%{X-Forwarded-For}i %v %u %t \"%r\" %s %b \"%{User-Agent}i\" \"%{Referer}i\""
九、Lighttpd开启Gzip
vim /etc/lighttpd/modules.conf
去掉
include "conf.d/compress.conf"
前面的#号注释
创建 /var/cache/lighttpd/compress 文件夹
mkdir -p /var/cache/lighttpd/compress
vim /etc/lighttpd/conf.d/compress.conf //添加要压缩的文件类型
compress.filetype = ("text/plain", "text/html", "application/x-javascript", "text/css", "application/javascript", "text/javascript")
压缩php
vim /usr/local/php/etc/php.ini
找到
zlib.output_compression = Off
把Off设置为On
zlib.output_compression_level 建议参数值是1~5,6以实际压缩效果提升不大,cpu占用却是几何增长
还可以找到
zlib.output_handler
设置为
zlib.output_handler = On
但是两者只能同时用一种
静态资源缓存时间的调整(mod_expire),在modules.conf文件中打开,后修改conf.d中相应文件,参考:
server.modules += ( "mod_expire" )
$HTTP["url"] =~ "(\.png|\.css|\.js|\.jpg|\.gif|\.ico|\.jpeg|\.swf)$"{
expire.url = ( "" => "access 2 months" ) }
参考:
https://mos.meituan.com/library/35/how-to-install-lighttpd-php-mysql-on-centos6/
http://i.linuxtoy.org/docs/guide/ch23s03.html
Leave a Reply
You must be logged in to post a comment.