windows7中Apache上的虚拟主机

时间:2014-04-29 14:57:01

标签: php windows apache xampp virtualhost

我试图在apache(xampp) in windows7 - x64上配置我的虚拟主机。

我放了这样的东西,

NameVirtualHost *:80

<VirtualHost *:80>
   DocumentRoot "C:/xampp/htdocs/projects/mysite/public"
   ServerName www.mysite.com 
   ErrorLog "logs/www.mysite.com-error.log"
   CustomLog "logs/www.mysite.com-access.log" common
</VirtualHost>

在我的主机文件(C:\Windows\System32\drivers\etc\hosts)中,我放了这样的东西,

127.0.0.1       localhost
127.0.0.1       mysite.com

我在浏览器上运行它,

http://www.mysite.com -

找不到服务器

Firefox无法在www.mysite.com找到服务器。

我是否错过了配置的内容?任何想法..

2 个答案:

答案 0 :(得分:0)

您的主机文件需要

    127.0.0.1       localhost
    127.0.0.1       mysite.com
    127.0.0.1       www.mysite.com

因为mysite.com和www.mysite.com不一样。我建议将ServerAlias添加到vhost.conf中并更改ServerName

    NameVirtualHost *:80

    <VirtualHost *:80>
       DocumentRoot "C:/xampp/htdocs/projects/mysite/public"
       ServerName mysite.com
       ServerAlias www.mysite.com 
       ErrorLog "logs/www.mysite.com-error.log"
       CustomLog "logs/www.mysite.com-access.log" common
    </VirtualHost>

答案 1 :(得分:0)

试试这个..

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName mysite.com 
    ServerAlias www.mysite.com
    DocumentRoot "C:/xampp/htdocs/projects/mysite/public" #Make sure that your httpd.conf file has DocumentRoot set to your htdocs folder or the folder in which your site is in.
    CustomLog logs/site.com.access.log combined
    ErrorLog logs/site.com.error.log
</VirtualHost>