重点在于启用mod_proxy模块,去掉前面的;号
% [/ s( S# d% D8 E 请编辑lighttpd.conf,
/ K! C5 b5 `: K 找到:# Z" j% ]7 m* a7 V( [
server.modules = {
. ?: w/ j$ w# j: B3 p& \
) @3 T# b9 O% V7 S! E8 `然后在里面加一句:3 N4 A5 a" K; G1 p6 r9 Q1 ? G Z
"mod_proxy", F C$ j/ v+ w4 b% ?
: J* F: `: o. F; H& F! f3 p然后添加反向代理配置代码,如:$ K3 m, K! y# q' X/ s/ Y
[AppleScript] 纯文本查看 复制代码 proxy.balance = "hash"
proxy.server = ( "" => ( ( "host" => "10.0.0.10" ),
( "host" => "10.0.0.11" ),
( "host" => "10.0.0.12" ),
( "host" => "10.0.0.13" ),
( "host" => "10.0.0.14" ),
( "host" => "10.0.0.15" ),
( "host" => "10.0.0.16" ),
( "host" => "10.0.0.17" ) ) ) ; }9 J3 X9 z; i- ^$ K; {
以下是实例代码:
) U, f( M4 r, |! `+ t[AppleScript] 纯文本查看 复制代码 server.modules = (
"mod_access",
"mod_status",
"mod_proxy",
"mod_accesslog" )
server.document-root = "/srv/www/htdocs/"
server.errorlog = "/var/log/lighttpd/error.log"
status.status-url = "/server-status"
$HTTP["url"] !~ "\.(js|css|gif|jpg|png|ico|txt|swf|html|htm)$" {
proxy.server = ( "" => (
( "host" => "10.10.10.87", "port" => 80 )
)
)
}
1 t9 r/ r$ Z! L9 r1 C) O. x* J: |, r+ S: g1 h6 h* f w( w+ h
以下是一个配置文件,包含两个host,其中一个域全部被重定向到主域下:
% ~3 C6 E& ^% @- R, V0 a9 Z[AppleScript] 纯文本查看 复制代码 server.modules += ( "mod_proxy" )
$HTTP["host"] == "liaoxuefeng.com" {
url.redirect = ( "^/(.*)" => "http://www.liaoxuefeng.com/$1" )
}
$HTTP["host"] == "www.liaoxuefeng.com" {
server.name = "www.liaoxuefeng.com"
server.document-root = "/srv/liaoxuefeng.com/www/"
accesslog.filename = "/srv/liaoxuefeng.com/log/access.log"
server.errorlog = "/srv/liaoxuefeng.com/log/error.log"
$HTTP["url"] !~ "^(favicon.ico|.*/static/.*)$" {
proxy.server = ( "" => (( "host" => "127.0.0.1", "port" => 8000 )))
}
}
+ J4 \5 O; e" K
以上配置在lighttpd 1.4.x中测试通过。4 W7 Q+ r9 U: ~ M$ f
" e s( g* b# q1 h. b7 T代理 81 端口的服务 到 xxx.domain.com:
0 X; q( w# i, [* p) x[AppleScript] 纯文本查看 复制代码 # lighttpd.conf
$HTTP["host"] == "xxx.domain.com" {
proxy.balance = "hash"
proxy.server = (""=>
(
("host" =>"127.0.0.1","port"=>81)
)
)
}
{6 e: l4 H( P9 I0 d& o4 d' |# M
+ {" Q2 i( M# l2 I0 K% r2 M |