httpd-vhosts.conf – 为什么这个工作?

我在Windows 7上运行Apache 2.28,这是我的目录结构:

C:/

www(包含Apache服务器,它是免费的Web-Developer Server-Suite,这是C:/ www /的默认configuration)

虚拟主机

vhosts.1

vhosts.2

我添加到httpd-vhosts.conf:

<Directory C:/www/vhosts.1> Order Deny,Allow Allow from all </Directory> <Directory C:/www/vhosts.2> Order Deny,Allow Allow from all </Directory> 

但只是为了testing我可以把它们放在任何地方,然后我添加了一个虚拟主机,将该域添加到HOSTS文件,并将其放在C:/ www(主Webroot)中。

这是我添加的最新的域名:

 <VirtualHost *:80> ServerName testing-server-win7.co.uk ServerAlias www.testing-server-win7.co.uk DocumentRoot /www/testing-server-win7.co.uk ErrorLog /www/Apache22/logs/error.log <Directory "/www/testing-server-win7.co.uk"> Options All AllowOverride All order allow,deny allow from all </Directory> 

它的工作,令人惊讶的。

为什么是这样的,你能把它们放在Apache的任何地方吗?

这是一个开发服务器,顺便说一句,不对互联网开放 – 虽然电脑确实有互联网接入。

任何人都在这里尝试过,并为他们工作?

谢谢

我会猜测你需要改变你正在使用的斜线的方向: – 它应该是C:\而不是你有什么C:/

HTTP协议有一个名为Host的头域 。 这使得虚拟主机成为可能。

您的浏览器尝试访问您的主机文件转换为适当的IP的testing-server-win7.co.uk。
除了向该IP发送HTTP GET请求之外,它还会发送主机名(通过使用主机头字段),起初似乎是多余的,“服务器当然知道他自己的名字”。

Apache可以阅读这个,并找出你想要达到的网站。 然后,它为您服务的网站。


从文档 :

The <Directory> and <Files> directives, along with their regex counterparts, apply directives to parts of the filesystem. Directives enclosed in a <Directory> section apply to the named filesystem directory and all subdirectories of that directory.

换句话说,如果您在configuration文件中使用<Directory>标记引用文件系统的<Directory> ,则Apache可以从中为其提供服务。 你所要做的就是把它作为虚拟主机的文档根目录(就像你一样)。