admin 发表于 2012-11-22 00:43:28

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

重点在于启用mod_proxy模块,去掉前面的;号
请编辑lighttpd.conf,
找到:
server.modules = {

然后在里面加一句:
"mod_proxy",

然后添加反向代理配置代码,如:
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.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 )
      )
    )
}

以下是一个配置文件,包含两个host,其中一个域全部被重定向到主域下:
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 )))

    }
}

以上配置在lighttpd 1.4.x中测试通过。

代理 81 端口的服务 到 xxx.domain.com:
# lighttpd.conf
$HTTP["host"] == "xxx.domain.com" {

proxy.balance = "hash"
proxy.server = (""=>
    (
      ("host" =>"127.0.0.1","port"=>81)
    )
)
}


页: [1]
查看完整版本: lighttpd作为代理服务器的配置例子