Apache VirtualDocumentRoot 最佳设置

发布于 2024-09-30 13:39:35 字数 1530 浏览 1 评论 0原文

我希望使用 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。%1+ 在 http://abc.example.com,会给我 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 几乎是可能的)。

干杯,

JP

I want to have a clean, efficient directory setup with VirtualDocumentRoot. (Reference: http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html).

In particular, I am thinking of the following:

1) http://example.com to be served by /apache_root/example.com

2) http://www.example.com to be served by /apache_root/www/example.com OR /apache_root/example.com/www OR /apache_root/example.com (any one of these is fine. But I don't want to use redirect for the sake of efficiency).

3) http://abc.example.com should be served by /apache_root/example.com/abc (Basically, it should be directory inside /apache_root/example.com)

Now comes the tricky part::

All of the above can be achieved using the directory name Interpolation methods listed here:
http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html#interpol

BUT::

How to take care of the fact that example.com can actually even be example.co.in ??

(For base directory, if I use %2+ on example.co.in, it will give me co.in but I want example.co.in. %1+ on http://abc.example.com, will give me abc.example.com as base directory instead of example.com which I want).

Basically, I want a rule that will work consistently for:
1) www.abc.example.com
2) abc.example.com
3) www.abc.example.co.in
4) abc.example.co.in

(Note: Apparently, the maximum levels in domain name is 127 http://en.kioskea.net/contents/internet/dns.php3. That means 0.1.2.3.4.example.com is pretty much possible).

cheers,

JP

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏见 2024-10-07 13:39:35

如果您只有 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>

您明白了。

If you've got just 2 domains you can simply 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>

You get the idea.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文