项目

通用

个人资料

操作

增强型虚拟主机

模块:mod_evhost

描述

mod_evhost 根据包含以下内容的模式构建文档根目录
通配符。这些通配符可以表示提交的主机名的一部分

  %% => % sign
  %0 => domain name + tld
  %1 => tld
  %2 => domain name without tld
  %3 => subdomain 1 name
  %4 => subdomain 2 name
  %_ => full domain name
  %{M.N} => single character at 1-indexed position N in the domain segment %M (e.g %0 - %9) (since 1.4.43)
evhost.path-pattern = "/home/www/servers/%3/pages/"

请注意,evhost.path-pattern 中的 % 模式具有上述特殊含义。它们与 url.redirect 和 url.rewrite-* 中的 % 替换具有相同的含义。

选项

evhost.path-pattern
用于替换以构建文档根目录的带通配符模式

示例

用户虚拟主机

  $HTTP["host"] =~ "users\.example\.org" {
      evhost.path-pattern = "/home/%4/public_html/" 
  }

http://johndoe.users.example.org/ => /home/johndoe/public_html/

自 lighttpd 1.4.43 起

  $HTTP["host"] =~ "users\.example\.org" {
      evhost.path-pattern = "/home/%{4.1}/%4/public_html/" 
  }

http://johndoe.users.example.org/ => /home/j/johndoe/public_html/

通用示例

  server.document-root = "/home/user/sites/default/site" 
  evhost.path-pattern  = "/home/user/sites/%0/site/" 

如果请求 example.org,并且找到 /home/user/sites/example.org/site/,则该路径将成为文档根目录。

如果请求 example.net 但不存在名为 /home/user/sites/example.net/site/ 的目录,则文档根目录仍为 /home/user/sites/default/site

一个糟糕的示例

  server.document-root = "/home/user/sites/" 
  evhost.path-pattern  = "/home/user/sites/%0/site/" 

server.document-root 绝不应指向包含 evhost 子目录的目录。
原因如下:假设 foo.example.com 和 bar.example.com 都指向服务器。
假设 /home/user/sites/foo.example.com/site 存在,但 /home/user/sites/bar.example.com/site 不存在。

如果 foo.example.com 通过 mod_auth 配置

  $HTTP["host"] == "foo.example.com" {
    auth.require = ( "/" => ...
    ) 
  }

我们可以通过访问 http://bar.example.com/foo.example.com/site/ 来绕过已配置的认证。

更新者 gstrauss 8 年多以前 · 23 次修订