lighttpd配置实例

news/2024/8/26 13:08:49

lighttpd异常自动重启脚本

1.建立脚本 
vi /root/bin/check_lighttpd.sh

#!/bin/bash 
date=`date  +%Y-%m-%d-%H-%M` 
if curl –head  http://www.gaojinbo.com/index.html | grep "200" >/dev/null 2>&1 ; then 
echo lighttpd is ok $date >>/root/bin/check_lighttpd.log 
else 
echo lighttpd is error $date >>/root/bin/check_lighttpd.log 
/etc/init.d/lighttpd restart 
fi

 

 

2.增加执行权限 
chmod +x /root/bin/check_lighttpd.sh

 

 

3.添加到crontab 
*/10    *       *       *       *       /root/bin/check_lighttpd.sh

 

 

===========================

lighttpd配置gzip压缩

 

编辑配置文件 
vi /etc/lighttpd/lighttpd.conf

 

1.开启 
            "mod_compress",

 

 

2.添加类似配置

$HTTP["host"] =="www.gaojinbo.com" { 
server.document-root ="/www/web/gaojinbo.com/www"

$HTTP["url"] =~ "^/static/" { 
compress.cache-dir          = "/www/tmp/lighttpd-compress/" 
compress.filetype           = ("text/plain", "text/html", "application/x-javascript", "text/css","application/javascript", "text/javascript") 
}

}

 

=====================

cronolog分割lighttpd的日志

 

Cronolog是一款日志轮循(rotation)工具,可以用它来把Apache、Tomcat等Web服务器上输出的日志切分成按日或月保存的文件。

 

1.源码安装cronolog 
cd /opt 
wget http://cronolog.org/download/cronolog-1.6.2.tar.gz 
tar zxvf ../cronolog-1.6.2.tar.gz 
cd cronolog-1.6.2 
./configure 
make && make install

 

2.修改lighttpd配置文件使用cronolog进行日志rotate 
#vi /etc/lighttpd.conf

server.errorlog             = "|/usr/local/sbin/cronolog /var/log/lighttpd/error/%Y/%m/%d/error.log"

accesslog.filename          = "|/usr/local/sbin/cronolog /var/log/lighttpd/access/%Y/%m/%d/access.log"

保存后重启lighttpd使配置生效。如果配置成功,系统进程里将会多出两个cronolog的进程,新的日志将保存在配置目录中按照年月日建立文件夹下

 

==================

lighttpd控制fastcgi进程数

 

lighttpd默认的fastcgi产生数是8
如果要增加或者减少fastcgi进程数
就需要修改配置文件,进行定制

fastcgi.server             = ( “.php” =>
( “localhost” =>
(
“socket” => “/var/run/lighttpd/php-fastcgi.socket”,
“bin-path” => “/usr/local/php/bin/php-cgi”,
“min-procs” => 1,
“max-procs” => 1,
“bin-environment” => (
“PHP_FCGI_CHILDREN” => “3”,
),
“bin-copy-environment” => (
“PATH”, “SHELL”, “USER”
),

 

“idle-timeout” => 20
)
)
)

就是PHP_FCGI_CHILDREN参数.控制fastcgi进程的产生数
有一点要注意
如果使用ea,xcache或者APC等等OPCODE加速器
一定要将max-procs设置为1
否则可能会产生问题.

 

========================

lighttpd限制IP访问指定URL

 

WEB服务器 
lighttpd

1.编辑配置文件 
vi /etc/lighttpd/lighttpd.conf 
#example 
$HTTP["host"] == "gaojinbo.com" { 
status.status-url = "/server-status" 
server.name = "gaojinbo.com" 
server.document-root = "/www/www.gaojinbo.com" 
$HTTP["remoteip"] !~ "119.107.106|129.145.100.138" { 
    $HTTP["url"] =~ "^/server-status" { 
      url.access-deny = ( "" ) 
    } 

}

 

2.重启服务 
/etc/init.d/lighttpd restart

完成!

 

附: 
Task: Match on the remote IP

For example block access to http://theos.in/stats/ url if IP address is NOT 192.168.1.5 and 192.168.1.10 (restrict access to these 2 IPs only):

Open /etc/lighttpd/lighttpd.conf file 
# vi /etc/lighttpd/lighttpd.conf 
Append following configuration directive:

$HTTP["remoteip"] !~ "200.19.1.5|210.45.2.7" { 
    $HTTP["url"] =~ "^/stats/" { 
      url.access-deny = ( "" ) 
    } 
}

Save and restart lighttpd: 
# /etc/init.d/lighttpd restart


http://www.niftyadmin.cn/n/3040892.html

相关文章

google proto buffer实战

使用与Thrift类似—— 下载EXE https://developers.google.com/protocol-buffers/docs/downloads Demo地址 https://developers.google.com/protocol-buffers/docs/javatutorial#compiling-your-protocol-buffers 中有addressbook.proto内容 举例子:放在 D:\Users\g…

sniper的中文翻译的pdf版本 BSD ROOTKIT 设计

sniper的中文翻译的pdf版本http://www.zif.cn/bsdrootkit.pdf转载于:https://blog.51cto.com/axlrose/1292982

PostgreSQL 10 build-in table partition(Range)

1.下载 rpm知识库包操作系统版本:CentOS Linux release 7.2.1511 (Core) X64[rootlocalhost home]# yum install https://download.postgresql.org/pub/repos/yum/testing/10/redhat/rhel-7-x86_64/pgdg-centos10-10-1.noarch.rpm Preparing... …

一次Mysql故障诊断过程

一次Mysql故障诊断过程<?xml:namespace prefix o ns "urn:schemas-microsoft-com:office:office" />作者&#xff1a;田逸([email]sery163.com[/email]) from: [url]http://netsecurity.51cto.com/art/200803/67632.htm[/url]那天因参加MS的新品发布大会&a…

protocol buffer开发文档

欢迎来到protocol buffer开发文档。protocol buffers是一个语言无关、平台无关、序列化结构数据可扩展的用来协议交互、数据存储等的解决方案。本文档的目标受众是那些想要在他们的应用中使用protocol buffer的Java&#xff0c;C或者Python开发者。这个总览将介绍protocol buff…

如何删除写保护的文件_Windows小知识:如何删除“不能”删除的文件?

我们来看看如何删除那些“不能”删除的文件&#xff0c;比如&#xff1a;FlashHelperServiceZhuDongFangYu(这个别乱搞&#xff0c;删了360可能会出问题&#xff1f;)其实&#xff0c;“不能”删除只是看起来不能删而已&#xff0c;并不表示真的就删除不了。不能删除的原因分析…

一个专科出来的计算机学生,月薪两万是否不切实际?

实话实说&#xff0c;不切实际谈不上&#xff0c;但很难。专科生在职场上受到的学历歧视比知乎里大多数人意识到的要强的多。跟很多人想的不同&#xff0c;招人大多数情况下并不是面试官自己拍板就算的&#xff0c;大点的厂子和企业&#xff0c;都要走一套流程&#xff0c;任何…

用swift开发仪表盘控件(二)

二、代码分析 这个控件本质就是从UIView继承的一个类而已。所以整个代码事实上就是一个定制的UIView类。 依据UIView的规则进行例如以下初始化&#xff1a; required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } override init(frame: CGRect) { self.poin…