创build子域 – LocalHost上的Apache虚拟主机

我在标题中的问题可能是错误的,但我没有其他的想法如何说出来。 (专家请帮助这个?)。

当我到达URL http://subdomain.localhost时,基本上子域在我的开发机器上工作。 我想要实现的是使用http://subdomain.jacques加载相同的网站。 jacques是我电脑的名字。

这是我在我的Windows hosts文件。

 127.0.0.1 localhost localhost localhost jacques localhost subdomain.127.0.0.1 subdomain.localhost subdomain.localhost subdomain.localhost subdomain.jacques subdomain.localhost 

这是我在vhosts.conf文件中。

 ServerName localhost DocumentRoot "c:\web" <VirtualHost jacques:80 jacques *:80> <Directory "c:\web"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Order Allow,Deny Allow from all Require all granted </Directory> ServerName localhost ServerAlias localhost DocumentRoot "c:\web" </VirtualHost> <VirtualHost subdomain.jacques *:80> ServerName subdomain.localhost ServerName subdomain.jacques ServerAlias subdomain.localhost ServerAlias subdomain.jacques DocumentRoot "C:\xampp\htdocs\subdomain" DirectoryIndex index.html index.php <Directory "C:\xampp\htdocs\subdomain"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Order Allow,Deny Allow from all Require all granted </Directory> </VirtualHost> 

我在阅读Apache网站上的文档时尝试过:

  • 将PC名称添加到<VirtualHost>标签。
  • 将另一个ServerName / ServerAlias添加到虚拟主机
  • 在Windows中将条目添加到hosts文件中

我不知道自己做错了什么,所以即使你能回答这个问题,也请指点一下正确的方向。

系统详情

  • 操作系统 :Windows 10
  • Apache版本 :2.4
  • PHP版本 :5.4(不知道这是否有用,甚至相关。)
  • Apache安装path c:\amp\apache
  • PHP安装path c:\amp\php

这是我在我的Windows主机文件。

这是错误的格式。 必须是 – “ip地址fqdn”

 127.0.0.1 localhost jacques subdomain.localhost subdomain.jacques 

至于虚拟主机

 <VirtualHost *:80> ServerName localhost DocumentRoot "c:\web" <Directory "c:\web"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Order Allow,Deny Allow from all Require all granted </Directory> </VirtualHost> <VirtualHost *:80> ServerName subdomain.localhost ServerAlias subdomain.jacques DocumentRoot "C:\xampp\htdocs\subdomain" DirectoryIndex index.html index.php <Directory "C:\xampp\htdocs\subdomain"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Order Allow,Deny Allow from all Require all granted </Directory> </VirtualHost> 

您可以使用域(和任何子域)lvh.me进行testing。 当它parsing为127.0.0.1。 所以不需要编辑主机文件

 # host lvh.me lvh.me has address 127.0.0.1 lvh.me mail is handled by 10 mail.lvh.me. # host subdomain.lvh.me subdomain.lvh.me has address 127.0.0.1