【问题标题】:Apache VirtualDocumentRoot best settingApache VirtualDocumentRoot 最佳设置
【发布时间】:2011-05-02 19:34:29
【问题描述】:

我想使用 VirtualDocumentRoot 进行干净、高效的目录设置。 (参考:http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html)。

特别是,我正在考虑以下几点:

1) http://example.com 由 /apache_root/example.com 提供服务

2) http://www.example.com 由 /apache_root/www/example.com 或 /apache_root/example.com/www 或 /apache_root/example.com 提供服务(其中任何一个都可以。但我不想要为了效率而使用重定向)。

3) http://abc.example.com 应该由 /apache_root/example.com/abc 提供服务(基本上应该是 /apache_root/example.com 内的目录)

现在是棘手的部分::

以上所有都可以使用这里列出的目录名称插值方法来实现: http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html#interpol

但是::

如何处理 example.com 实际上甚至可以是 example.co.in 的事实??

(对于基本目录,如果我在 example.co.in 上使用 %2+,它将给我 co.in,但我想要 example.co.in。在 http://abc.example.com 上使用 %1+,会给我 abc。 example.com 作为基本目录,而不是我想要的 example.com)。

基本上,我想要一个始终适用的规则: 1) www.abc.example.com
2) abc.example.com 3) www.abc.example.co.in 4) abc.example.co.in

(注意:显然,域名的最大级别是 127 http://en.kioskea.net/contents/internet/dns.php3。这意味着 0.1.2.3.4.example.com 几乎是可能的)。

干杯,

日本

【问题讨论】:

    标签: apache2 directory-structure virtualhost


    【解决方案1】:

    如果您只有 2 个域,则只需 2 个VirtualHosts

    <VirtualHost *:80>
      ServerDomain example.com
      ServerAlias *.example.com
      VirtualDocumentRoot /var/www/%-2%-1/%-3+
    </VirtualHost>
    <VirtualHost *:80>
      ServerDomain example.co.in
      ServerAlias *.example.co.in
      VirtualDocumentRoot /var/www/%-3%-2%-1/%-4+
    </VirtualHost>
    

    你明白了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-07
      • 1970-01-01
      • 1970-01-01
      • 2011-05-03
      • 2010-10-21
      • 1970-01-01
      • 2010-09-11
      • 2014-01-25
      相关资源
      最近更新 更多