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

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

问题描述

我怎么可以设置Apache的默认虚拟主机?
preferably,我想默认主机不相同的IP地址的主机。现在,我有这样的事情:

how can I set a default VirtualHost in apache? 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 *>

如果域从/ someOtherDir /加载转发到我的服务器上,而不是在这个vhost.conf文件,文件,符合市场预期。但是,我希望能够使用不同的根为其未添加到vhost.conf文件(还)的IP地址本身和域。这可能吗?

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?

编辑:纠正我的code位,所以它看起来更像实际vhost.conf文件

edit: corrected my code a bit, so it looks more like the actual vhost.conf file

推荐答案

我找到了答案:我记得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天全站免登陆