简体   繁体   English

Apache虚拟主机-服务器IP定向到虚拟主机而不是/ var / www / html

[英]Apache virtual hosts - server ip directing to virtual host instead of /var/www/html

I have set up a linux box mainly for testing and I have got to a stage were apache, mysql and php are running. 我已经设置了一个主要用于测试的linux机器,并且已经进入了一个阶段,apache,mysql和php正在运行。 I followed tutorials on how to set up virtual hosts so I can point domains to it but something strange is happening. 我遵循了有关如何设置虚拟主机的教程,以便可以将域指向它,但是正在发生一些奇怪的事情。 This is my httpd-vhosts.conf file that I have included in my httpd.conf file: 这是我包含在httpd.conf文件中的httpd-vhosts.conf文件:

NameVirtualHost *:80

<VirtualHost *:80>
  ServerName thedomain.co.uk
  DocumentRoot /var/www/thedomain
</VirtualHost>

When I go to thedomain.co.uk it is pointing to the correct place as you'd expect. 当我转到thedomain.co.uk时,它指向的是您期望的正确位置。 But when I go to my servers ip, internal or external it is going to the same directory as the virtual host. 但是,当我将服务器ip(内部或外部)转到虚拟主机所在的目录时。 Could you guys think of any reason that is? 你们能想到是什么原因吗? I would expect it to go to /var/www/html by default? 我希望它默认转到/ var / www / html吗? Oh and I'm running CentOS 6.3 哦,我正在运行CentOS 6.3

Thanks in advance for any answers! 预先感谢您的任何回答!

You have used wildcard to point everything at DocumentRoot /var/www/thedomain 您已使用通配符将所有内容都指向DocumentRoot /var/www/thedomain

You need to create second listing : 您需要创建第二个清单:

<VirtualHost myotherdomain.co.uk:80>
  ServerName myotherdomain.co.uk
  DocumentRoot /var/www/myotherdomain
</VirtualHost>

where your other domain is whatver ip and the document root, points to your choise. ip和文档根目录都是您的其他域所指向的位置。

The first vhost listing is also used as the default ... so if you were to use localhost it would resolve to whatever is first in list. 第一个虚拟主机列表也用作默认列表...因此,如果您要使用localhost,它将解析为列表中第一个列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM