找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 17197|回复: 0

lighttpd作为代理服务器的配置例子

[复制链接]
发表于 2012-11-22 00:43:28 | 显示全部楼层 |阅读模式
重点在于启用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
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|第一站论坛 ( 蜀ICP备06004864号-6 )

GMT+8, 2026-7-11 17:24 , Processed in 0.087134 second(s), 24 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表