重点在于启用mod_proxy模块,去掉前面的;号, N8 B8 d* t( {; y
请编辑lighttpd.conf,
" K* y% s7 {+ ^ 找到:
9 K8 z4 b. m7 b0 B8 ~ ^; Z2 t* Vserver.modules = {- J9 l/ P9 G& Z4 \! g7 R
: O: N6 E- U; b0 ~! ]% V
然后在里面加一句:4 U9 J) r" c) s' P/ n
"mod_proxy",# w; L8 j: ]" s' s; S* T
+ W, f: v( O$ w& L+ Y8 W% e* k然后添加反向代理配置代码,如:6 c+ C& [+ ]( S8 ]/ D6 N
[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" ) ) )
, g& t0 |( }- S- L$ e) R以下是实例代码:+ d/ t$ x; \0 l
[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 )
)
)
} " z" E( l! I' Q2 W8 T
" o4 w# ]' t3 @
以下是一个配置文件,包含两个host,其中一个域全部被重定向到主域下:
! c4 j8 W: Y0 u. n/ m9 ~[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 )))
}
}
1 } `) w9 z- `& i/ y' c
以上配置在lighttpd 1.4.x中测试通过。, l, h# z$ Y$ w2 @( V5 N
' z7 S- X' e% a8 y代理 81 端口的服务 到 xxx.domain.com:
! ]8 }. A& U$ ^1 }, Z/ w" w" J; E[AppleScript] 纯文本查看 复制代码 # lighttpd.conf
$HTTP["host"] == "xxx.domain.com" {
proxy.balance = "hash"
proxy.server = (""=>
(
("host" =>"127.0.0.1","port"=>81)
)
)
}
3 k+ g: O) W1 }- p
. q4 s+ x8 c; Y; k7 Y
|