2013-07-16 115 views
5

我想在我的本地主机(XAMPP)上创建一个虚拟主机。想尽组合在那里,但我总是加载,而不是特定的文件夹xampp虚拟主机 - 总是加载htdocs

这里的htdocs是hosts文件:

127.0.0.1 localhost 
::1 localhost 
127.0.0.1 devsnappy 

这里是httpd-vhosts.conf

NameVirtualHost *:80 
<VirtualHost *:80> 
    DocumentRoot E:/xampp/htdocs/snappy/public 
    ServerName devsnappy 
    <Directory "E:/xampp/htdocs/snappy/public"> 
     Options Indexes FollowSymLinks Includes ExecCGI 
     AllowOverride All 
     Order allow,deny 
     Allow from all 
    </Directory> 
</VirtualHost> 

有什么建议?

+2

您是否正确重启httpd? – avignat

回答

6

这里是一个guide到虚拟主机添加到XAMPP

看来你错过hosts文件的东西。

例如,假设您有另一个ClientB网站。你会添加127.0.0.1 clientB.local>在hosts文件和C:\ XAMPP的\ apache的\的conf \额外\的httpd-vhosts.conf应该是这样的:

NameVirtualHost * 
    <VirtualHost *> 
    DocumentRoot "C:\xampp\htdocs" 
    ServerName localhost 
    </VirtualHost> 
    <VirtualHost *> 
    DocumentRoot "C:\Documents and Settings\Me\My Documents\clientA\website" 
    ServerName clientA.local 
    <Directory "C:\Documents and Settings\Me\My Documents\clientA\website"> 
    Order allow,deny 
    Allow from all 
    </Directory> 
</VirtualHost> 
<VirtualHost *> 
    DocumentRoot "C:\Documents and Settings\Me\My Documents\clientB\website" 
    ServerName clientB.local 
    <Directory "C:\Documents and Settings\Me\My Documents\clientB\website"> 
    Order allow,deny 
    Allow from all 
    </Directory> 
</VirtualHost> 

而且重启 httpd

+0

我不认为这与'hosts'文件有关。更好的猜测是,他只是在修改'httdp-vhosts.conf'后忘记重启apache服务器。 – Cyclonecode

+0

我复制粘贴指南中的示例...更改路径...重新启动并工作...然后更改回我的自定义虚拟主机名称...重新启动和工作...我不完全是pb是什么(这个指南是我做的第一个),但是如果有人和我有相同的pb,那么可以帮助按照这个答案...谢谢所有 – user2030809

+0

+1 - 对不起,我的错误虽然你说的是/ etc/hosts '文件。 – Cyclonecode

1

呵呵,让我在Apache 2.4.9中工作真的很痛苦。我发现很多教程,但是我无法使它工作。

我的解决方案是Apache 2.4及以上VERSION.I已与Apache 2.4.9

测试它,你需要编辑两个files.PLEASE使此两种文件备份在您做出CHANGES.If你写什么错误,即使您卸载xampp,然后再次安装xampp,您的本地主机也不起作用。

STEP 1:

编辑这个文件

C:\ WINDOWS \ SYSTEM32 \ DRIVERS \等\主机

打开使用 “运行方式管理员联系” 从记事本文件(非常重要)。您可以通过

开始菜单>记事本做>右键点击>运行作为管理员联系>打开文件

这个文件

127.0.0.1  testsite.dev 
127.0.0.1  www.testsite.dev 

要么你去testsite.dev或www.testsite.dev的末尾添加这两条线,它现在将尝试从本地计算机无法通过Web

步骤2:

E:\ xampp \ apache \ conf \ extra \ httpd-vhosts。CONF

您可以正常编辑这个文件,也没有必要运行此文件作为“运行方式管理员联系” 添加follwing线在该文件的末尾

NameVirtualHost *:80 
<VirtualHost *:80> 
    DocumentRoot "E:/xampp/htdocs" 
    ServerName localhost 
</VirtualHost> 

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    DocumentRoot "E:/xampp/htdocs/htc" 
    ServerName testsite.dev 
    ServerAlias www.testsite.dev 
</VirtualHost> 

我在E盘setmy XAMPP ,所以当你从这里复制,请确保你改变它根据你的XAMPP installation.the最后一部分是有点有趣。我指出这个药水

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    DocumentRoot "E:/xampp/htdocs/htc" 
    ServerName testsite.dev 
    ServerAlias www.testsite.dev 
</VirtualHost> 

在哪里可以找到这个代码?在互联网上,你可以在很多地方找到它,但可能不会k,因为该代码将与Apache版本区分开来.SO解决方案是什么?

在文件结尾处,您会看到有一些注释行已经向您演示如何设置虚拟主机,只需复制这些行并进行必要的更改,并且可以为您工作。我附上了截图为了更好的理解

http://postimg.org/image/5pug9f42p/

4

对于任何人谁读这并没有解决方案的帮助你,这是什么帮助了我。

只是取消注释此行包含在httpd.conf:

# Virtual hosts 
Include etc/extra/httpd-vhosts.conf 

这样的话,它会让你在等/额外/ 的httpd-vhosts.conf可用所做的更改!

之后不要忘记重启Apache服务器!

+1

保存了我的一天。谢谢<3 <3:*:* – Mia