lighttpd 配置文件

news/2024/6/19 0:01:09

原文地址:lighttpd 配置文件 作者:bfz814

/etc/lighttpd/lighttpd.conf为 Lighttpd 服务器的配置文件
## 网站根目录 映射在机器上的物理路径
server.document-root        = "/home/lighttpd/html/"

## 如果网站目录中出现以下文件名,不用指定文件名便可直接访问
index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm" )

## Lighttpd 进程的归属用户
server.username             = "nobody"

## Lighttpd 进程的归属群组
server.groupname            = "nobody"

## 绑定到端口 默认为 80
#server.port                = 81

## 绑定到地址 默认为 所有
#server.bind                = "127.0.0.1"

## 访问日志 路径
accesslog.filename          = "/var/log/lighttpd/access.log"

## 错误日志 路径
server.errorlog             = "/var/log/lighttpd/error.log"

## 禁止访问以下文件
url.access-deny             = ( "~", ".inc" )  

## 与目录列表相关的设置
#dir-listing.activate       = "enable"  
#dir-listing.encoding       = "utf8"
#dir-listing.show-readme       = "enable"

配置文件中的server.modules字段决定Lighttpd使用哪些扩展模块:

server.modules = ("mod_access","mod_fastcgi","mod_accesslog" )
  • Lighttpd 通过 mod_fastcgi 模块支持 PHP
  • mod_accesslog 模块为访问纪录

其实在 /etc/lighttpd/lighttpd.conf 文件中,这部分内容写在多行,方便用 # 作注释,禁用不需要的模块

server.modules              = (
## 基础模块
        "mod_access",
## 访问纪录
        "mod_accesslog" )   
## fastcgi 支持
        "mod_fastcgi",
## cgi 支持
#                               "mod_cgi",
## 路径绑定
#                               "mod_alias",
##  代理 (转发页面)
#                               "mod_proxy",
## 虚拟主机
#                               "mod_evhost",
## 输出压缩
#                               "mod_compress",
## 网址重写
#                               "mod_rewrite",
## 用户认证
#                               "mod_auth",
#                               "mod_redirect",
#                               "mod_cml",
#                               "mod_trigger_b4_dl",
#                               "mod_status",
#                               "mod_setenv",
#                               "mod_simple_vhost",
#                               "mod_userdir",
#                               "mod_ssi",
#                               "mod_usertrack",
#                               "mod_expire",
#                               "mod_secdownload",
#                               "mod_rrdtool",

fastcgi 配置

在配置文件的server.modules字段中启用mod_fastcgi模块,然后检查以下内容:

### fastcgi 脚本扩展名
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )      

### fastcgi 服务器设置      
fastcgi.server             = ( ".php" =>
                               ( "localhost" =>
                                 (
# TCP/IP 接口 (“套接字”)
                                   "socket" => "/tmp/php-fastcgi.socket",
# PHP cgi 模式的可执行文件(PHP 有 cli 和 cgi 两种模式)
                                   "bin-path" => "/usr/bin/php-cgi"
                                 )
                               )
                            )

上面例子的第二部分,使用 Lighttpd 转发规则。大意为: .php文件按以下方式处理 => 从localhost(本地),发送到/tmp/php-fastcgi.socket接口,使用/usr/bin/php-cgi处理。写成一行比较直观:

fastcgi.server  = ( ".php" => ( "localhost" => ( "socket" => "/tmp/php-fastcgi.socket", "bin-path" => "/usr/bin/php-cgi" )))

如果想要 fastcgi 和 PHP 协同工作,还需要对 PHP 作一些设置,见“PHP&MySQL”一节

proxy

该模块可以将文件转发到其它服务器进行处理,例如将.jsp文件转发到Tomcat服务器

### 首先启用 mod_proxy 模块
# += 表示在原来设置上增加
servers.modules +=( "mod_proxy")

### 设置 proxy 服务器转发规则    
proxy.server               = ( ".jsp" =>
                               ( "localhost" =>
                                 (
# 将 .jsp 文件发送到 地址“127.0.0.1”的“8080”端口(也就是本机的 Tomcat 服务器)
                                   "host" => "127.0.0.1",
                                   "port" => 8080
                                 )
                               )
                             )

CGI

Lighttpd 可以支持 cgi

### 启用 mod_cgi 模块
server.modules              += ("mod_cgi")

### 设置 cgi 解释器
cgi.assign                 = ( ".pl"  => "/usr/bin/perl",
                               ".cgi" => "/usr/bin/perl",
                               ".py"  => "/usr/bin/python" )

路径绑定

将一个路径,映射到网站目录中

## 启用 mod_alias 模块
servers.modules +=( "mod_alias")    

##  将 /home/lighttpd/html/man 映射到 http://host/docs
alias.url += ( "/docs" => "/home/lighttpd/html/man" )

虚拟主机

Lighttpd 可以建立多个虚拟主机,绑定在不同的网络接口

### 启用 mod_evhost 模块
servers.modules +=( "mod_evhost")

### 虚拟主机绑定的网络接口
$HTTP["host"] == "192.168.1.2" 
{
### 虚拟主机可以使用独立的选项
dir-listing.activate       = "enable"
dir-listing.encoding       = "utf8"
dir-listing.show-readme       = "enable"
### 虚拟主机根目录
server.document-root = "/home/user/html"
### 虚拟主机路径绑定
alias.url = ( "/download/" => "/home/user/downloads/" )
alias.url += ( "/pictures/" => "/home/user/pictures/" )
}


[43] 查看/etc/init.d/lighttpd文件,可以看到类似字句:
/usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf

- f 选项指定配置文件


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

相关文章

常见职位、职务英文译名

常见职位、职务英文译名http://www.gter.net 2003-7-7 15:27:58 新东方 作者: 无论是在你出国前准备各种材料、办理各种手续,还是在您到达异国需要求职或申请入 学,您肯定要经常用到一些职位、职务的名称。找找看,您现在的职位英文怎么说&…

FastCGI编程介绍

CGI(Common Gateway Interface)公共网关接口,是HTTP服务器与其他程序通信的工具。FastCGI是一个long-live型的CGI,支持分布式计算,它将CGI解释器进程保持在内存中并因此获得较高的性能。 FastCGI工作方式是接受Web服务…

Python调用DLL问题请教

发信人: Insomnia (Garfield), 信区: Python标 题: Python调用DLL问题请教发信站: BBS 水木清华站 (Fri Aug 6 09:19:43 2004), 转信 背景:Python 2.3.3, ctypes 0.9.0, Matlab R14目的:想采用Python作为“粘合剂”将已有的大量的MATLAB下的程序&…

本机ip、127.0.0.1和0.0.0.0区别

本机ip、127.0.0.1和0.0.0.0区别网络javaIP地址的记法:IP地址由四个字节构成,为了方便阅读和书写,每个字节用0-255的数字表示,字节之间用’.分割,如:10.10.152.235有时候我们会看到这样的IP:10.…

Hibernate入门之自己写的小例子的总结 zz

俺是新学Hibernate的,望大家不要见笑。 本机环境介绍: JB7.0 hibernate-2.0.3 Oracle8.1客户端 数据库: 局域网内的服务器上的Oracle8.1 服务器IP地址:x.x.x.x 端口:1521 数据库名:OraHib &#xf…

iptables 的mangle表

mangle表的主要功能是根据规则修改数据包的一些标志位,以便其他规则或程序可以利用这种标志对数据包进行过滤或策略路由。 内网的客户机通过Linux主机连入Internet,而Linux主机与Internet连接时有两条线路,它们的网关如图所示。现要求对内网进…

黄帝世系

来源: http://proxy4.smth.org/pc/pccon.php?id2793&nid69960&sall 题记:跟前面的系列文章相同,仍是综合了网上查来的各种信息,简单分析,尽量合理取舍,但未经严格考证,权当一种了解而…

炎帝世系

来源: http://proxy4.smth.org/pc/pccon.php?id2793&nid69961&sall 题记:跟前面的系列文章相同,仍是综合了网上查来的各种信息,简单分析,尽量合理取舍,但未经严格考证,权当一种了解而…