第 4 章 Lighttpd

简介:

目录

4.1. 安装Lighttpd
4.1.1. quick install with aptitude
4.1.2. yum install
4.1.3. to compile and then install lighttpd
4.1.3.1. shell script
4.2. /etc/lighttpd/lighttpd.conf
4.2.1. max-worker / max-fds
4.2.2. accesslog.filename
4.2.3. ETags
4.2.4. server.tag
4.3. Module
4.3.1. simple_vhost
4.3.2. ssl
4.3.3. redirect
4.3.4. rewrite
4.3.4.1. Lighttpd Rewrite QSA
4.3.5. alias
4.3.6. auth
4.3.7. compress
4.3.8. expire
4.3.9. status
4.3.10. setenv
4.3.10.1. Automatic Decompression
4.3.11. fastcgi
4.3.11.1. enable fastcgi
4.3.11.1.1. spawn-fcgi
4.3.11.1.2. php-fpm
4.3.11.2. PHP
4.3.11.2.1. 编译安装PHP
4.3.11.2.2. apt-get install
4.3.11.3. Python
4.3.11.3.1. Django
4.3.11.3.2. Python Imaging Library
4.3.11.4. Perl
4.3.11.4.1. Installing lighttpd and FastCGI for Catalyst
4.3.11.5. Ruby
4.3.11.6. UNIX domain sockets
4.3.12. user-agent
4.3.13. spdy
4.4. 其他模块
4.4.1. mod_secdownload 防盗链
4.5. Example
4.5.1. s-maxage

4.1. 安装Lighttpd

4.1.1. quick install with aptitude

if you OS is Ubuntu/Debian

apt-get install lighttpd
netkiller@shenzhen:~$ sudo apt-get install lighttpd
		

the config file in /etc/lighttpd

netkiller@shenzhen:~/document/Docbook/Linux$ find /etc/lighttpd/
/etc/lighttpd/
/etc/lighttpd/lighttpd.conf
/etc/lighttpd/conf-enabled
/etc/lighttpd/conf-available
/etc/lighttpd/conf-available/10-userdir.conf
/etc/lighttpd/conf-available/10-fastcgi.conf
/etc/lighttpd/conf-available/10-cgi.conf
/etc/lighttpd/conf-available/README
/etc/lighttpd/conf-available/10-ssl.conf
/etc/lighttpd/conf-available/10-proxy.conf
/etc/lighttpd/conf-available/10-auth.conf
/etc/lighttpd/conf-available/10-simple-vhost.conf
/etc/lighttpd/conf-available/10-ssi.conf
		

Enabling and disabling modules could be done by provided e.g.

/usr/sbin/lighty-enable-mod fastcgi
/usr/sbin/lighty-disable-mod fastcgi
		

when you enabled a mod please force-reload it

netkiller@shenzhen:/etc/lighttpd$ sudo lighty-enable-mod fastcgi
Available modules: auth cgi fastcgi proxy simple-vhost ssi ssl userdir
Already enabled modules: userdir
Enabling fastcgi: ok
Run /etc/init.d/lighttpd force-reload to enable changes
netkiller@shenzhen:/etc/lighttpd$ sudo /etc/init.d/lighttpd force-reload
 * Stopping web server lighttpd                                                                                                                                                                                                                                                                                       [ OK ]
 * Starting web server lighttpd
		

4.1.2. yum install

# yum install lighttpd lighttpd-fastcgi -y
# chkconfig lighttpd on
		

创建缓存目录

# mkdir -p /var/cache/lighttpd/compress
# chown lighttpd:lighttpd -R /var/cache/lighttpd
		

禁用ipv6

# vim /etc/lighttpd/lighttpd.conf

#server.use-ipv6 = "enable"
		

4.1.3. to compile and then install lighttpd

  1. 下载相关软件

    立即下载

    $ sudo apt-get install libpcre3*
    
    cd /usr/local/src/
    wget http://www.lighttpd.net/download/lighttpd-1.4.15.tar.gz
    tar zxvf lighttpd-1.4.15.tar.gz
    cd lighttpd-1.4.15
    				
  2. 编译安装

    ./configure --prefix=/usr/local/lighttpd-1.4.15 \
    --with-bzip2 \
    --with-memcache
    make
    make install
    				
  3. 创建目录与配置文件

    ln -s /usr/local/lighttpd-1.4.15/ /usr/local/lighttpd
    mkdir -p /www/pages
    mkdir /www/logs
    mkdir /usr/local/lighttpd/htdocs
    mkdir /usr/local/lighttpd/logs
    mkdir /usr/local/lighttpd/etc
    cp ./doc/lighttpd.conf /usr/local/lighttpd/etc/
    cd /usr/local/lighttpd/
    				
  4. 配置lighttpd.conf

    vi etc/lighttpd.conf

    找到 server.modules

    删除 mod_fastcgi 前的注释

    跟据你的需求修改下面定义

    server.document-root = "/usr/local/lighttpd/htdocs/"

    server.errorlog = "/usr/local/lighttpd/logs/lighttpd.error.log"

    accesslog.filename = "/usr/local/lighttpd/logs/access.log"

    注释 $HTTP["url"]

    #$HTTP["url"] =~ "\.pdf$" {
    #  server.range-requests = "disable"
    #}
    				
  5. 运行lighttpd

    /usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/etc/lighttpd.conf
    				

    测试

    curl http://ip/ 因为/www/pages/下没有HTML页面所以返回:

    404 - Not Found

4.1.3.1. shell script

lighttpd script

例 4.1. /etc/init.d/lighttpd

					
#!/bin/bash
# lighttpd init file for web server
#
# chkconfig: - 100 100
# description: Security, speed, compliance, and flexibility--all of these describe LightTPD which is rapidly redefining efficiency of a webserver;
#				as it is designed and optimized for high performance environments.
# author: Neo Chen<openunix@163.com>
#
# processname: $PROG
# config:
# pidfile: /var/run/lighttpd

# source function library
. /etc/init.d/functions

PREFIX=/usr/local/lighttpd
PROG=$PREFIX/sbin/lighttpd
OPTIONS="-f /usr/local/lighttpd/etc/lighttpd.conf"
USER=daemon
RETVAL=0
prog="lighttpd"

start() {
        echo -n $"Starting $prog: "
        if [ $UID -ne 0 ]; then
                RETVAL=1
                failure
        else
                daemon --user=$USER $PROG $OPTIONS
                RETVAL=$?
                [ $RETVAL -eq 0 ] && touch /var/lock/subsys/lighttpd
        fi;
        echo
        return $RETVAL
}

stop() {
        echo -n $"Stopping $prog: "
        if [ $UID -ne 0 ]; then
                RETVAL=1
                failure
        else
                killproc $PROG
                RETVAL=$?
                [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/lighttpd
        fi;
        echo
        return $RETVAL
}

reload(){
        echo -n $"Reloading $prog: "
        killproc $PROG -HUP
        RETVAL=$?
        echo
        return $RETVAL
}

restart(){
	stop
	start
}

condrestart(){
    [ -e /var/lock/subsys/lighttpd ] && restart
    return 0
}

case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	restart
        ;;
  reload)
	reload
        ;;
  condrestart)
	condrestart
	;;
  status)
        status lighttpd
	RETVAL=$?
        ;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
	RETVAL=1
esac

exit $RETVAL
					
	





原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

目录
相关文章
|
6月前
阿里云盘企业版收费标准:不同人数、存储空间价格表
2025年阿里云盘企业版推出全新收费标准,首月免费试用,费用较原规格最多节省87%。新版CDE提供不同用户数和存储空间组合,如5人500GB/年169.9元、20人2TB/年749元等。具体价格及详细对比请参考官方页面或文章解析。 了解更多:[阿里云盘企业版CDE](https://www.aliyun.com/product/storage/pds/cde?source=5176.29345612&userCode=r3yteowb)
1071 54
|
10月前
|
机器学习/深度学习 安全 物联网
智能时代下的数据安全:挑战与对策
本文深入探讨了在快速发展的信息技术背景下,数据安全面临的新挑战及应对策略。文章首先分析了当前数据泄露和滥用的风险,随后提出了一系列针对性的技术和管理措施,旨在增强个人和企业的数据防护能力。通过案例分析,本文揭示了数据保护的最佳实践,并对未来数据安全技术的发展方向进行了展望。
|
10月前
|
开发者
【开发者评测】阿里云百炼评测获奖名单
阿里云百炼评测获奖名单正式公布!
170 12
|
存储 Cloud Native 关系型数据库
阿里云PolarDB、RDS获评信通院数据库Serverless认证最高“先进级”,AnalyticDB获“增强级”
在日前中国信通院组织的数据库产品能力评测中,阿里云PolarDB for MySQL、RDS MySQL数据库顺利完成了首批事务型数据库Serverless能力分级测试,获最高“先进级”评级;AnalyticDB MySQL和AnalyticDB PostgreSQL顺利完成了首个分析型数据库Serverless能力分级测试,获评“增强级”评级。
阿里云PolarDB、RDS获评信通院数据库Serverless认证最高“先进级”,AnalyticDB获“增强级”
|
关系型数据库 MySQL Unix
一分钟了解 sync、fsync、fdatasync 系统调用
Hi,大家好!我是白日梦。 今天我要跟你分享的话题是:“了解fsync这个系统调用嘛?谈谈看!”
880 0
|
弹性计算 负载均衡 容灾
阿里云服务器地域及可用区选择攻略
阿里云服务器地域及可用区选择攻略
1453 0
阿里云服务器地域及可用区选择攻略
|
设计模式 算法 Java
Java的生成器模式(又名建造者模式),你真的会了吗(上)
Java的生成器模式(又名建造者模式),你真的会了吗(上)
539 0
Java的生成器模式(又名建造者模式),你真的会了吗(上)
安诺云联合阿里云国内首推批量计算,助力三代Canu组装加速
随着测序技术的不断发展,大量基因组学数据被积累,对于数据分析软件的要求也越来越高,尤其是在做基因组组装分析时,软件的计算资料消耗和分析周期往往是研究者不得不考虑的问题。Canu[1]是一款目前广泛使用的三代基因组组装软件,文章发表短短两年时间,引用的次数已接近1000次,其中不乏顶级的CNS期刊。
3156 0
|
人工智能
阿里发布颠覆性研究:AI 首次具备“自主判案”能力
AI 在垂直领域的智能化水平还很初级?这个观感已经过时了。阿里达摩院发布了一项新研究:AI 进化到助理法官水平,可一秒“判案”。
1249 0