分享

lighttpd配置之代理、负载均衡(mod_proxy)

 用勿龍潛 2012-11-02
lighttpd配置之代理、负载均衡(mod_proxy)
使用proxy可以使lighttpd成为一个代理服务器。例如将java的请求全都转向给jboss来处理
mod_proxy有三个标签:
proxy.debug,0或者1. 表示是否启动调试模式。 1表示启动
proxy.balance,使用负载均衡的模式。可以使“hash”,“round-robin”,”fair”三种模式之一。
’round-robin’ 交替轮训, ‘hash’ 根据请求的url产生一个 hash值,来确保同样的请求的url都访问同样的主机
‘fair’ is the normal load-based, passive balancing.

语法结构

1
2
3
4
5
6
7
8
9
 ( <extension> => 
      ( [ <name> => ]
        ( "host" => <string> ,
          "port" => <integer> ),
        ( "host" => <string> ,
          "port" => <integer> )
      ),
      <extension> => ... 
    )

* : 表示请求url的文件扩展名或者文件前缀 (如果以”/”开始); 可以是空 (“”) 表示所有的请求
* : 可选名称
* “host”: 被代理的服务器的ip
* “port”: 被代理服务器的端口,默认是80

如:

1
2
3
4
5
6
proxy.server = ( ".jsp" =>
                       ( ( 
                           "host" => "10.0.0.242",
                           "port" => 8080
                         ) )
                     )

再如:

1
2
3
4
5
6
7
8
$HTTP["host"] == "www.domain.me" {
        proxy.server  = ( "" =>
        ( ( 
                "host" => "127.0.0.1",
                "port"=>"8080"  
        ) ) 
        )
}

负载均衡的例子,例如有8个squid缓存,需要用lighttpd做负载均衡

1
2
3
4
5
6
7
8
9
10
11
  $HTTP["host"] == "www.example.org" {
    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" ) ) )
  }

当一个服务器宕机后,它上面的请求将被转移给其他设备server

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多