在Windows 10上的xampp apache服务器v-3.2.1中创建多个虚拟主机

3

我试图在我的Windows 10,64位,XAMPP 3.2.1上创建多个虚拟主机。

我按照以下步骤进行:

1- C:\Windows\System32\drivers\etc\hosts

我在hosts文件的底部添加了以下行:

127.0.0.1 smc
127.0.0.1 ocms

2- D:\xampp\apache\conf\httpd.conf

虚拟主机已经启用,请参考以下内容:

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

3- D:\xampp\apache\conf\extra\httpd-vhosts.conf

我在httpd-vhosts.conf文件中添加了以下代码块:

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

<VirtualHost *:80>
    ServerName smc
    DocumentRoot "D:/vhosts/smc"
    SetEnv APPLICATION_ENV "development"
    <Directory "D:/vhosts/smc/">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName ocms
    DocumentRoot "D:/vhosts/ocms/"
    SetEnv APPLICATION_ENV "development"
    <Directory "D:/vhosts/ocms">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

最终,我将我的两个目录放在了D:/vhosts/文件夹中:
D:/vhosts/ocms
D:/vhosts/smc

当我重启了我的Apache服务器并测试了URL,例如:

http://ocms

或者
http://smc

它返回以下错误:
Access forbidden!

You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.

If you think this is a server error, please contact the webmaster.
Error 403
ocms
Apache/2.4.12 (Win32) OpenSSL/1.0.1l PHP/5.6.8 

我在过去三四天里已经搜索了太多次,也阅读了一些关于如何在XAMPP上创建虚拟主机的帖子,例如how to create virtual host on XAMPP,但是没有成功。请告诉我我错过了什么。

谢谢
2个回答

0

你的初始设置对我来说很好用。

我认为你的问题是缺少索引。

这行代码将强制 Apache 只接受 index.php 文件作为入口点:

DirectoryIndex index.php

然而,如果您的入口点具有不同的名称或扩展名,则会出现错误:

You don't have permission to access the requested directory. There is either no index document or the directory is read-protecte

0

好的,我已经完成了。我必须将所有目录放在htdocs文件夹下面,像这样的结构。

D:\xampp\htdocs
D:\xampp\htdocs\test\smc
D:\xampp\htdocs\test\ocms

感谢大家宝贵的时间


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接