添加VirtualHost失败:访问禁止错误403(XAMPP)(Windows 7)

时间:2012-02-02 09:50:19

标签: apache windows-7 xampp virtualhost vhosts

我在Windows 7上运行了一个XAMPP安装。

只要我将一个VirtualHost添加到httpd-vhosts.conf,“常规”http://localhost和新的dropbox.local都无效。

这是我添加到httpd-vhosts.conf中的内容:

<VirtualHost *:80>
    ServerAdmin postmaster@dummy-host.localhost
    DocumentRoot "E:/Documenten/Dropbox/Dropbox/dummy-htdocs"
    ServerName dropbox.local
    ServerAlias www.dropbox.local
    ErrorLog "logs/dropbox.local-error.log"
    CustomLog "logs/dropbox.local-access.log" combined
</VirtualHost>

所以我查看了我的dropbox.local-error.log以获取任何信息:

[Thu Feb 02 10:41:57 2012] [error] [client 127.0.0.1] client denied by server configuration: E:/Documenten/Dropbox/Dropbox/dummy-htdocs/

这个错误似乎可以通过添加

来解决
<directory "E:/Documenten/Dropbox/Dropbox/dummy-htdocs">
     Allow from all
</directory>

但现在我在dropbox.local-error.log中收到此错误:

[Thu Feb 02 10:45:56 2012] [error] [client ::1] Directory index forbidden by Options directive: E:/Documenten/Dropbox/Dropbox/dummy-htdocs/

此外,当我尝试访问http://localhost时,我在常规error.log中没有收到任何错误,但在我尝试访问时会收到error 403

任何人都可以帮忙......这让我很生气:S

编辑: 同样在httpd.conf中有以下内容(我已经多次提到它,所以在有人说之前):

<IfModule dir_module>
    DirectoryIndex index.php index.pl index.cgi index.asp index.shtml index.html index.htm \
                   default.php default.pl default.cgi default.asp default.shtml default.html default.htm \
                   home.php home.pl home.cgi home.asp home.shtml home.html home.htm
</IfModule>

9 个答案:

答案 0 :(得分:320)

好的:这就是我现在所做的,它已经解决了:

我的httpd-vhosts.conf现在看起来像这样:

<VirtualHost dropbox.local:80>
    DocumentRoot "E:/Documenten/Dropbox/Dropbox/dummy-htdocs"
    ServerName dropbox.local
    ErrorLog "logs/dropbox.local-error.log"
    CustomLog "logs/dropbox.local-access.log" combined
    <Directory "E:/Documenten/Dropbox/Dropbox/dummy-htdocs">
        # AllowOverride All      # Deprecated
        # Order Allow,Deny       # Deprecated
        # Allow from all         # Deprecated

        # --New way of doing it
        Require all granted    
    </Directory>
</VirtualHost>

首先,我看到有必要设置<Directory xx:xx>选项。所以我将<Directory > [..] </Directory> - 部分放在<VirtualHost > [..] </VirtualHost>内。 之后,我将AllowOverride AuthConfig Indexes添加到<Directory>选项。

现在http://localhost也指向了dropbox-virtualhost。所以我将dropbox.local添加到<VirtualHost *:80>,这使其成为<VirtualHost dropbox.local:80>

最终它有效:D!

我是一个快乐的人! :):)

我希望其他人可以使用这些信息。

答案 1 :(得分:56)

当我将“目录”内容更改为此内容时,我工作了:

<Directory  "*YourLocation*">
Options All
AllowOverride All
Require all granted  
</Directory>

答案 2 :(得分:9)

对我来说(在Windows 7上也是XAMPP),这是有用的:

<Directory "C:\projects\myfolder\htdocs">`
   AllowOverride All
   Require all granted
   Options Indexes FollowSymLinks
</Directory>` 

这一行会导致403:

Order allow,deny

答案 3 :(得分:8)

我在Windows 7上使用XAMPP 1.6.7。This article为我工作。

我在httpd-vhosts.conf的文件C:/xampp/apache/conf/extra中添加了以下行 我还取消了对行# NameVirtualHost *:80

的注释
<VirtualHost mysite.dev:80>
    DocumentRoot "C:/xampp/htdocs/mysite"
    ServerName mysite.dev
    ServerAlias mysite.dev
    <Directory "C:/xampp/htdocs/mysite">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

重新启动apache之后,它仍然无法正常工作。 然后我必须通过编辑文件C:/Windows/System32/drivers/etc/hosts来跟随文章中提到的步骤9。

# localhost name resolution is handled within DNS itself.
     127.0.0.1       localhost
     ::1             localhost
     127.0.0.1       mysite.dev  

然后我开始工作http://mysite.dev

答案 4 :(得分:5)

谢谢,这很有效!但我取代了这个

AllowOverride AuthConfig Indexes

AllowOverride All

否则,.htaccess不起作用:我遇到了RewriteEngine的问题,错误信息“RewriteEngine不允许在这里”。

答案 5 :(得分:3)

以上建议对我没有用。我使用灵感从我的窗户上运行它 http://butlerccwebdev.net/support/testingserver/vhosts-setup-win.html

对于httpd-vhosts.conf中的Http

<Directory "D:/Projects">       
AllowOverride All
Require all granted
</Directory>

##Letzgrow
<VirtualHost *:80>
DocumentRoot "D:/Projects/letzgrow"
ServerName letz.dev
ServerAlias letz.dev    
</VirtualHost>

在httpd-ssl.conf中使用Https(Open SSL)

<Directory "D:/Projects">       
AllowOverride All
Require all granted
</Directory>

##Letzgrow
<VirtualHost *:443>
DocumentRoot "D:/Projects/letzgrow"
ServerName letz.dev
ServerAlias letz.dev    
</VirtualHost>

希望它有所帮助!!

答案 6 :(得分:0)

我正在使用xampp 1.7.3。从这里使用灵感:xampp 1.7.3 upgrade broken virtual hosts access forbidden

INSTEAD OF在 httpd-vhosts.conf 中添加<Directory> .. </Directory>,我在<Directory "D:/xampplite/cgi-bin"> .. </Directory>之后立即将其添加到 httpd.conf

这是我在httpd.conf中添加的内容:

<Directory "D:/CofeeShop">
    AllowOverride All
    Options  All
    Order allow,deny
    Allow from all
</Directory>

这是我在httpd-vhosts.conf中添加的内容

<VirtualHost *:8001>
    ServerAdmin postmaster@dummy-host2.localhost
    DocumentRoot "D:/CofeeShop"
    ServerName localhost:8001
</VirtualHost>

我还在httpd.conf中添加Listen 8001来完成我的设置。

希望有所帮助

答案 7 :(得分:0)

对于很多人来说这是一个许可问题,但对我来说,事实证明错误是由我试图提交的形式中的错误引起的。具体来说,我在“行动”的价值后意外地放了一个“大于”的标志。所以我建议你再看看你的代码。

答案 8 :(得分:0)

经过如此多的更改,然后尝试并回答。 对于

  

SO: Windows 7
   Xampp版本:Xampp或Xampp Portable 7.1.18
  安装程序:win32-7.1.18-0-VC14-installer

  • 请勿编辑其他文件,例如httpd-xampp
  • 停止Apache
  • 将以下内容添加到位于**your_xampp_directory**\apache\conf\extra\
  • 的httpd-vhosts.conf中
  • 在以下行(大约20行)之前删除哈希:NameVirtualHost *:80
  • 添加代码并在目录中进行更改:

      <VirtualHost *:80>
           DocumentRoot "F:/Web/htdocs/"
           ServerName localhost
    </VirtualHost>
      <VirtualHost *:80>
      DocumentRoot "F:/myapp/htdocs/"
      ServerName test1.localhost
      <Directory  "F:/myapp/htdocs/">
                Options All
                AllowOverride All
                Require all granted  
            </Directory>
      </VirtualHost>
    
  • 编辑(具有管理员访问权限)您的主机文件(位于Windows \ System32 \ drivers \ etc,但有以下提示,每个域只有一个回送ip:

127.0.0.1 localhost 127.0.0.2 test1.localhost 127.0.0.3 test2.localhost 对于每个实例,重复第二个块,第一个块仅是针对“默认”目的的主要块