shitou's blog 
Home About Feed | MIX BOY 塌客

Tags "lighttpd"

16
Oct

Lighttpd配置参数 by shitou

0
在Lighttpd的wiki上看大一篇很好的文档,里面也有troubleshooting, 转过来了,本来是想找Lighttpd防webspider的资料的,
根据下面的说明使用$HTTP["useragent"]这个变量可以达到效果


#!rst
==================
Configuration File
==================

------------
Module: core
------------

.. meta::
:keywords: lighttpd, configuration

.. contents:: Table of Contents

Description
===========

Basic Syntax
------------

A BNF like notation: ::

option : NAME = VALUE
merge : NAME += VALUE
NAME : modulename.key
VALUE : ( | | | | VALUE [ + VALUE ]*)
: "text"
: digit*
: ( "enable" | "disable" )
: "(" [ "=>" ] [, [ "=>" ] ]* ")"
INCLUDE : "include" VALUE
INCLUDE_SHELL : "include_shell" STRING_VALUE

Example
-------

::

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

# TCP port
server.port = 80

# selecting modules
server.modules = ( "mod_access", "mod_rewrite" )

# variables, computed when config is read.
var.mymodule = "foo"
server.modules += ( "mod_" + var.mymodule )
# var.PID is initialised to the pid of lighttpd before config is parsed

# include, relative to dirname of main config file
include "mime.types.conf"

# read configuration from output of a command
include_shell "/usr/local/bin/confmimetype /etc/mime.types"

Conditional Configuration
=========================

Most options can be configured conditionally by using the following syntax
(including nesting).

::

{
...
{
... nesting: match only when parent match
}
}
else {
... the "else if" block
}

where is one of one of the following:

$HTTP["cookie"]
match on cookie
$HTTP["host"]
match on host
$HTTP["useragent"]
match on useragent
$HTTP["referer"]
match on referer
$HTTP["url"]
match on url. If there are nested blocks, this must be the most inner block.
$HTTP["querystring"]
match on querystring, eg, after the ? in this type url: index.php?module=images..
$HTTP["remoteip"]
match on the remote IP or a remote Network (Warning: doesn't work with IPv6 enabled)
$HTTP["scheme"] (Introduced in version 1.4.19)
match on the scheme used by the incoming connection. This is either "http" or "https".
$SERVER["socket"]
match on socket. Value must be on the format "ip:port" where ip is an IP address and
port a port number, or ":port" to match port only. Only equal match (==) is supported.
It also binds the daemon to this socket. Use this if you want to do IP/port-based virtual hosts.
$PHYSICAL["path"] (Introduced in version 1.5.0)
match on the mapped physical path of the file / cgi script to be served.
$PHYSICAL["existing-path"] (Introduced in version 1.5.0)
match on the mapped physical path of the file / cgi script to be served
only if such a file exists on the local filesystem.

is one of:

==
string equal match
!=
string not equal match
=~
perl style regular expression match
!~
perl style regular expression not match

and is either a quoted ("") literal string or regular expression.

Example
-------

::

# disable directory-listings for /download/*
dir-listing.activate = "enable"
$HTTP["url"] =~ "^/download/" {
dir-listing.activate = "disable"
}

# handle virtual hosting
# map all domains of a top-level-domain to a single document-root
$HTTP["host"] =~ "(^|\.)example\.org$" {
server.document-root = "/var/www/htdocs/example.org/pages/"
}

# multiple sockets
$SERVER["socket"] == "127.0.0.1:81" {
server.document-root = "..."
}

$SERVER["socket"] == "127.0.0.1:443" {
ssl.pemfile = "/var/www/certs/localhost.pem"
ssl.engine = "enable"

server.document-root = "/var/www/htdocs/secure.example.org/pages/"
}

# deny access for all googlebot
$HTTP["useragent"] =~ "Google" {
url.access-deny = ( "" )
}

# deny access for all image stealers (anti-hotlinking for images)
$HTTP["referer"] !~ "^($|http://www\.example\.org)" {
url.access-deny = ( ".jpg", ".jpeg", ".png" )
}

# deny the access to www.example.org to all user which
# are not in the 10.0.0.0/8 network
$HTTP["host"] == "www.example.org" {
$HTTP["remoteip"] != "10.0.0.0/8" {
url.access-deny = ( "" )
}
}

# Allow only 200.19.1.5 and 210.45.2.7 to
# have access to www.example.org/admin/
$HTTP["host"] == "www.example.org" {
#!~ is a perl style regular expression not match
$HTTP["remoteip"] !~ "^(200\.19\.1\.5|210\.45\.2\.7)$" {
$HTTP["url"] =~ "^/admin/" {
url.access-deny = ( "" )
}
}
}

Troubleshooting
---------------

If you're not running on the default port, $HTTP["host"] will have the port appended to it,
so regular expressions ending in "$" (without allowing for a port) won't match.
To match with or without a port, change "(^|\\.)example\\.org$" to "(^|\\.)example\\.org(\\:[0-9]*)?$"

advanced usage
==============
check the blog:
http://blog.lighttpd.net/articles/2005/05/07/advanced-configuration-in-up-upcoming-1-4-x

Using variables
===============

You can set your own variables in the configuration to simplify your config.
::

var.basedir = "/home/www/servers/"
$HTTP["host"] == "www.example.org" {
server.name = "www.example.org"
include "incl-base.conf"
}

in incl-base.conf:
server.document-root = basedir + server.name + "/pages/"
accesslog.filename = basedir + server.name + "/logs/access.log"

You can also use environment variables or the default variables var.PID and
var.CWD: ::

var.basedir = env.LIGHTTPDBASE

$HTTP["host"] == "www.example.org" {
server.name = "www.example.org"
include "incl-base.conf"
include "incl-fastcgi.conf"
}

in incl-fastcgi.conf:
fastcgi.server = ( ... => ((
"socket" => basedir + server.name + "/tmp/fastcgi-" + PID + ".sock"
)) )

Or like the lighttpd script for rails does: ::

var.basedir = var.CWD

server.document-root = basedir + "/public/"

Some useful things that can NOT be done in lighttpd config (you need to
create a script in a real programming language and than use include_shell): ::

# testing if a variable has been set is NOT possible
var.not_sure_if_it_exists == undefined { ... set to default value ... }

# removing from arrays is NOT possible
server.modules -= ( "mod_idontwantyou" )

Global context
==============

::

global {
...
}

You don't need it in the main configuration file. But you might have
difficulty setting a server wide configuration inside a included-file from
conditionals.

Example
-------

::

in lighttpd.conf:
server.modules = ()
$HTTP["host"] == "www.example.org" {
include "incl-php.conf"
}

in incl-php.conf:
global {
server.modules += ("mod_fastcgi")
static-file.exclude-extensions += (".php")
}
fastcgi.server = "..."

Options
=======

`All Configuration Options`__

.. __: http://trac.lighttpd.net/trac/wiki/Docs%3AConfigurationOptions


Tags: lighttpd

2008-10-16 15:53:36, 5884 reviews

send to mailbox

Your email:

Tags

U-ka saegusa IN db command Mai Kuraki Norah Jones log iPhoneException ACG Mac Safari objective-c CouchDB LVS AJAX debian 推荐 AMQP google mail bug gettext Erlang 北京 iptables 架构 tips mysql backup function 我看 postfix 监控 SEO cache Etag memcache thread 进程 线程 无锡 yield file column mixboy xml rss gems ruby shitou shell lighttpd 安全 csrf 公司 nginx linux 模块 apache webserver 朋友 大学 生活 尼古拉斯凯奇 movie 文件同步 笑笑 歌词 auto complete plugin rails music ubuntu blog

Category

  • iPhone[17]
  • Erlang[4]
  • google[8]
  • 生活[38]
  • 音乐[11]
  • 电影[11]
  • linux[20]
  • web server[6]
  • mail server[3]
  • cluster[1]
  • system manage[5]
  • ruby[18]
  • ruby on rails[27]
  • 开源[3]

Episode

  • iPhoneException
  • shell
  • thread
  • memcache

Recent Comments

  • comment2, xenical canada, 5528, prilosec packag...
  • comment3, nolvadex package insert, 2877, xenica...
  • comment2, http://www.freecodesource.com/user/pr...
  • comment6, http://www.freecodesource.com/user/pr...
  • comment3, xenical support, :'-), prilosec half ...
  • comment7, how many hydrocodone does it take to ...
  • comment3, oxycodone acetaminophen, :E, viagra d...
  • comment7, http://www.freecodesource.com/user/pr...
  • comment6, valium for pain, accompanying, xanax ...
  • comment4, oxycodone ingredients, 2732, buy viag...

Popular Posts

  • MySQL Innodb备份
  • 准备开始学习Erlang了(恶狼, 二郎..)
  • Lighttpd配置参数
  • iPhone上的HelloWorld终于跑起来了
  • Etag和Expire

Recommended Posts

  • Mai Kuraki -永远より ながく
  • U-ka saegusa IN db Final Best
  • Heaven Can Wait - Charlotte Gainsbou
  • Ruby遍历MemCached的key
  • Norah Jones - The fall
  • 请记得仰望梦想的姿势
  • Shell: 统计MySQL InnoDB表的大小
  • Rails Benchmark
  • 发送异常到邮箱
  • I Miss Nobody
  • Music4u, Vol. 1
  • my macbook
  • Mai Kuraki-Beautiful
  • 10首最伤情英文歌曲精选
  • Mai Kuraki - PUZZLE/Revive

Friends' blogs

  • levy
  • sphance
  • andreas

Login

   注册

留言 查看留言

留言

   取消

留言 查看留言


Statistics

  • 访问次数: 51170
  • 今天访问: 34
  • 日志: 172
  • 评论: 117
  • 音乐: 9
  • 用户: 149


 

just DO NOT support IE

close