我在Apache中有多个VirtualHosts,它们都在端口80上侦听,其ServerNames设置为不同的Web地址。当我直接进入ip地址时,Apache默认将我发送到其中一个网站。我想更改哪个虚拟主机处理对ip地址的请求。我该怎么做?
<!-- This is currently the default (probably because it's first alphabetically) -->
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName mywebsite.com
DocumentRoot /var/www/testingother
...
</VirtualHost>
<!-- I want this to be default -->
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName myotherwebsite.com
DocumentRoot /var/www/testing
...
</VirtualHost>
答案 0 :(得分:1)
来自我自己的apache配置文件:
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/html"
请注意,此DocumentRoot
位于VirtualHost
块之外。我会假设你有类似的东西,但如果没有,你可以这样设置。那会更容易弄乱他们出现的顺序。
答案 1 :(得分:0)
默认虚拟主机是第一个要加载的主机。
httpd.conf
或vhosts.conf
中时,只需更改虚拟主机的顺序。000-default
。如果请求包含未知或没有Host:标头,则始终为 从基于主名称的vhost(vhost)提供服务 地址/端口首先出现在配置文件中。)