标签: lighttpd

  • lighttpd添加反向代理功能

    1、启用lighttpd的反向代理模块:

    编辑/etc/lighttpd/modules.conf文件,找到以下代码:

    ##
    ## mod_proxy
    ##
    #include "conf.d/proxy.conf"

    去掉以下代码开头的“#”号即可

    #include "conf.d/proxy.conf"

    2、编辑/etc/lighttpd/lighttpd.conf文件,添加以下代码:

    #tomcat
    
    $HTTP["host"] =~ "(abc\.com|www\.abc\.com)$" {
    	proxy.balance = "hash" 
    	proxy.server  = ( "" => ( ( "host" => "127.0.0.1", "port" => 8080 ) ) )
    }

    3、重启lighttpd服务器

    service lighttpd restart

     

     

     

    关于匹配符的初步理解:

    == 意味着匹配规则将使用普通的方法

    =~ 意味着匹配规则将使用正则表达式?(未确定)

    !~ 意味着不匹配规则将使用正则表达式

    ^表示开头

     

     

     

     

    其他的一些配置参考:

     

    $HTTP["host"] =~ "(sway\.com\.cn|www\.sway\.com\.cn)$" {
    	server.document-root = "/home/xinsiwei.20150120.igongcha/ROOT"
    	$HTTP["url"] !~ "\.(gif|jpg|png|txt|html|css|js|swf)$" {
    		proxy.server  = ( "/" => ( ( "host" => "127.0.0.1", "port" => 8128 ) ) )
    	}
    }

    这个的意思是,除了gif|jpg|png|txt|html|css|js|swf外,其余请求全部转发到127.0.0.1:8128端口上去

     

    $HTTP["host"] == "liaoxuefeng.com" {
        url.redirect = ( "^/(.*)" => "http://www.sway.com.cn/$1" )
    }

    这个的意思是,所有域名为liaoxuefeng.com的请求,全部跳转到http://www.liaoxuefeng.com/上去,并且自动匹配并补充url地址

     

    $HTTP["host"] == "www.sway.com.cn" {
        server.name = "www.sway.com.cn"
        server.document-root = "/home/www/sway/"
    
        $HTTP["url"] !~ "^(favicon.ico|.*/static/.*)$" {
            proxy.server = ( "" => (( "host" => "127.0.0.1", "port" => 8000 )))
        }
    }

    这个的意思是,除了favicon.ico及文件夹为/static/的url外,将全部请求转发到8000端口上