2008-06-18

lighttpd配置子域名和重定向

关键字: lighttpd subdomain redirect
前提是域名服务商支持泛域名,加这样三条A记录
beyondrails.com       120.72.34.135
www. beyondrails.com   120.72.34.135
*.beyondrails.com     120.72.34.135


1,重定向beyondrails.com到www.beyondrails.com
$HTTP["host"] =~ "^beyondrails\.com$" {
  url.redirect = ( "^/(.*)" => "http://www.beyondrails.com/$1" )
}


2,二级域名端口转发
$HTTP["host"] =~ "^.*\.beyondrails\.com$" {
  proxy.balance = "hash"
  proxy.server = (
    "" => (("host" => "127.0.0.1", "port" => 9999))
  )
}


3,具体的lighttpd配置
$HTTP["host"] =~ "^.*\.beyondrails\.com$" {
  server.document-root = #...
}


lighttpd的URL Rewrites配置语法:
url.rewrite-once = ( "<regex>" => "<relative-uri>" )


正则表达式:
Patterns ("wildcards") are matched against a string
pecial characters:
        * . (full stop) - match any character
        * * (asterisk) - match zero or more of the previous symbol
        * + (plus) - match one or more of the previous symbol
        * ? (question) - match zero or one of the previous symbol
        * \? (backslash-something) - match special characters
        * ^ (caret) - match the start of a string
        * $ (dollar) - match the end of a string
        * [set] - match any one of the symbols inside the square braces.
        * (pattern) - grouping, remember what the pattern matched as a special variable
        * {n,m} - from n to m times matching the previous character (m could be ommited to mean >=n times)
Normal alphanumeric characters are treated as normal


替换模式:
If the matched regex contains groups in parentheses, $1..$9 in the replacement refer to the captured text in the matching group "$1" meaning the first group, "$2" the second, and so on.

You can also use certain meta-patterns in replacement text:
    * %% => % sign
    * %0 => domain name + tld (Top Level Domain, like .com or .net)
    * %1 => tld
    * %2 => domain name without tld
    * %3 => subdomain 1 name
    * %4 => subdomain 2 name
评论
发表评论

您还没有登录,请登录后发表评论

hideto
搜索本博客
我的相册
A6bdc31c-c66e-468e-961e-9cc721e82adc-thumb
screenshot
共 1 张
存档
最新评论