虚拟主机安装不起作用

虚拟主机安装不起作用

我正在尝试使用 xampp 安装我现有的本地服务器。我设置 apache 以将 mywebsite.dev 文档根目录指向 /code/www/public。我收到一条错误消息,提示“网页无法访问。此网站的地址与外部网站相同”。

我遵循的说明:

Create a folder on your computer for the files 
Edit your host file to add the site name 
Edit httpd-vhosts to add the VirtualHost 
Restart Apache using the XAMPP Control Panel 


127.0.0.1  //Mywebsite.dev

<VirtualHost *:80>
    DocumentRoot C:\Mywebsite\trunk\www\public
    ServerName //Mywebsite.dev    
    <Directory C:\Mywebsite\trunk\www\public>
        Order allow,deny
        Allow from all
    </Directory>   
</VirtualHost>

答案1

我收到一条错误消息,提示该网页无法访问。

您的配置中存在几处错误。

您的host文件:

127.0.0.1  //Mywebsite.dev
  • //从文件的条目中删除hosts

修正hosts文件:

127.0.0.1  Mywebsite.dev

您的httpd-vhosts.conf文件:

<VirtualHost *:80>
    DocumentRoot C:\Mywebsite\trunk\www\public
    ServerName //Mywebsite.dev    
    <Directory C:\Mywebsite\trunk\www\public>
        Order allow,deny
        Allow from all
    </Directory>   
</VirtualHost>
  • //从中删除ServerName

  • \用。。。来代替/

  • 引用DocumentRootDirectory

修正httpd-vhosts.conf文件:

<VirtualHost *:80>
    DocumentRoot "C:/Mywebsite/trunk/www/public"
    ServerName Mywebsite.dev    
    <Directory "C:/Mywebsite/trunk/www/public">
        Order allow,deny
        Allow from all
    </Directory>   
</VirtualHost>

答案2

为了解决禁止访问的问题,我在 httpd-conf 中进行了以下更改:

<Directory>
    AllowOverride none
    Require all denied
</Directory>

经过 :

 <Directory>
   Options Indexes FollowSymLinks Includes ExecCGI
   AllowOverride none
   Require all granted
</Directory>

相关内容