lighttpd配置子域名和重定向

前提是域名服务商支持泛域名,加这样三条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
[code]
$HTTP["host"] =~ "^beyondrails\.com$" {
url.redirect = ( "^/(.*)" => "http://www.beyondrails.com/$1" )
}
[/code]

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

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

[url=http://trac.lighttpd.net/trac/wiki/Docs%3AModRewrite]lighttpd的URL Rewrites配置语法[/url]:
[code]
url.rewrite-once = ( "" => "" )
[/code]

正则表达式:
[code]
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
[/code]

替换模式:
[code]
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
[/code]

你可能感兴趣的:(Infrastructure)