Apache 默认虚拟主机 [英] Apache default VirtualHost

查看:42
本文介绍了Apache 默认虚拟主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Apache 中设置默认 VirtualHost?

How can I set a default VirtualHost in Apache?

最好是,我希望默认主机与 IP 地址主机不同.现在我有这样的事情:

Preferably, I want the default host not to be the same as the IP address host. Now I have something like this:

NameVirtualHost *

<VirtualHost *>
    ServerAdmin admin@domain.com
    DocumentRoot /someOtherDir/
    ServerAlias ip.of.the.server
</VirtualHost>

<VirtualHost *>
    ServerAdmin admin@domain.com
    DocumentRoot /someroot/
    ServerAlias domain.com *.domain.com
</VirtualHost *>

如果一个域被转发到我的服务器,但不在这个 vhost.conf 文件中,那么/someOtherDir/中的文件会按预期加载.但我希望能够为 IP 地址本身和尚未添加到 vhost.conf 文件(尚未添加)的域使用不同的根.这可能吗?

If a domain is forwarded to my server, but isn't in this vhost.conf file, the files from /someOtherDir/ are loaded, as expected. But I want to be able to use a different root for the IP address itself and domains which aren't added to the vhost.conf file (yet). Is this possible?

推荐答案

我找到了答案:我记得如果没有找到其他匹配的块,Apache 会使用第一个块,所以我添加了一个没有 的块serveralias 在块的顶部:

I found the answer: I remembered that Apache uses the first block if no other matching block is found, so I've added a block without a serveralias at the top of the blocks:

NameVirtualHost *

<VirtualHost *>
    DocumentRoot /defaultdir/
</VirtualHost>

<VirtualHost *>
    ServerAdmin admin@domain.com
    DocumentRoot /someOtherDir/
    ServerAlias ip.of.the.server
</VirtualHost>

<VirtualHost *>
    ServerAdmin admin@domain.com
    DocumentRoot /someroot/
    ServerAlias domain.com *.domain.com
</VirtualHost>

这篇关于Apache 默认虚拟主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆