找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 16365|回复: 0

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

[复制链接]
发表于 2012-11-22 00:43:28 | 显示全部楼层 |阅读模式
重点在于启用mod_proxy模块,去掉前面的;号
# _) `! l" v7 |9 U: F  y 请编辑lighttpd.conf0 M7 ~% h9 O* T  Q
找到:
& z& b1 X1 M) G# ?$ G* U! Eserver.modules = {$ `, d/ `- u8 M3 O! `
9 I3 w' i, k$ P. J7 F
然后在里面加一句:
( P# u1 f5 t. m- B0 S6 X"mod_proxy",
, h' u$ A* V, X( ?- H/ {+ R# K$ d% k; J- ]* E1 M* ]- r  X
然后添加反向代理配置代码,如:
1 {  l0 _- o! ]7 E: j- L5 l
[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" ) ) )
+ W) L/ C( D5 D: N" C
以下是实例代码:& F1 \& h1 i$ }5 Z6 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 )
      )
    )
}
- e7 u: U# U4 w; N$ s& O
. c( I- f, {' W+ H4 g
以下是一个配置文件,包含两个host,其中一个域全部被重定向到主域下:1 x! M& R" r8 J2 f: d. o7 ^  |" M
[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 )))

    }
}

7 \: X0 B6 F& g+ ]以上配置在lighttpd 1.4.x中测试通过。6 f( Z) V# l2 ^' y* [' y. [1 w/ C
& x6 f- K8 c/ F  n
代理 81 端口的服务 到 xxx.domain.com:# F1 o# l' R6 e8 I, ~
[AppleScript] 纯文本查看 复制代码
# lighttpd.conf
$HTTP["host"] == "xxx.domain.com" {

  proxy.balance = "hash"
  proxy.server = (""=>
    (
      ("host" =>"127.0.0.1","port"=>81)
    )
  )
}
/ b5 i2 K1 L; v( h! d" f$ b! O
1 B* l6 A. z; h1 y
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2026-4-14 19:16 , Processed in 0.050054 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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