【问题标题】:I get Access Forbidden (Error 403) when setting up new alias设置新别名时出现 Access Forbidden (Error 403)
【发布时间】:2012-01-19 16:52:27
【问题描述】:

我正在运行 Windows 7,最近安装了 XAMPP 来构建开发环境。我对服务器端的东西不是很好,所以我在为项目设置别名时遇到了一些问题。

到目前为止,XAMPP 正在运行,如果我转到 localhost,我会看到 XAMPP 欢迎页面。我在我的 apache 安装的“conf”文件夹中创建了一个“alias”文件夹。在那里我添加了具有以下内容的 dev.conf:

<Directory "C:\Users\my_user\My%20Documents\Aptana%20Studio%203%20Workspace\project">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from 127.0.0.1
</Directory>

Alias /dev "C:\Users\my_user\My%20Documents\Aptana%20Studio%203%20Workspace\project"

但是当我转到“localhost/dev”时,我得到:

禁止访问!

您无权访问请求的对象。它要么是 服务器读保护或不可读。

如果您认为这是服务器错误,请联系网站管理员。

错误 403

我尝试使用谷歌搜索,并在 SO 上发现了其他类似的问题,但我似乎无法弄清楚。有人说你必须告诉它有权限,但在我的 conf 文件中我指定允许它来自 127.0.0.1。也许这是因为我的路径中有空格(尽管一些谷歌搜索告诉我 %20 工作)。我设法在不同的文件夹中创建了一个并复制粘贴了工作文件夹并更改了别名和路径,它坏了,所以这告诉我它可能与其中任何一个有关。

我查看了我的日志文件夹,发现以下行:

[2011 年 12 月 13 日星期二 14:59:20] [错误] [客户端 ::1] 客户端被拒绝 服务器配置:C:/Users/my_user/My%20Documents

我不确定它是否会减少,因为错误消息只能有一定的长度,但这绝对不是我在 dev.conf 文件中添加的路径,我希望这可以让一些人更清楚,因为我变得非常沮丧,我不知道该尝试什么了。

【问题讨论】:

  • 对于任何可能错过了这一点的人,就像我一样:您必须确保任何路径上都没有斜杠。我的别名中有斜杠,如下所示:Alias /aliasdir/ "D:/path/to/place"。其他一切都是正确的,但那个斜杠导致了 403。

标签: xampp


【解决方案1】:

我终于让它工作了。

我不确定路径中的空格是否会破坏某些内容,但我将 Aptana 安装的工作区更改为没有空格的内容。

然后我卸载了 XAMPP 并重新安装了它,因为我在想也许我在某个地方打错了字而没有注意到,并认为我应该从头开始工作。

原来 Windows 7 在某处有一个使用端口 80 的服务阻止 apache 启动(给它 -1)错误。于是我把它监听的端口改成了8080端口,不再冲突了。

最后我重新启动了我的计算机,出于某种原因,XAMPP 不喜欢我处理 ini 文件,而仅仅重新启动 apache 并没有解决问题。

无论如何,这是有史以来最令人沮丧的一天,所以我真的希望我的回答最终能帮助别人!

【讨论】:

  • 我会把钱花在“其他服务”上,即 Skype。如果您打开 Skype 并转到Tools &gt; Options &gt; Advanced &gt; Connection,然后查找显示使用端口 80 和 443 作为传入连接的替代选择的复选框。确保未选中。重新启动 Skype,然后您应该能够再次在端口 80 上运行 Apache。
  • @Adam:不一定是 Skype。我对 Dropbox 也有类似的问题,而且更改其所需的端口似乎不像 Skype 那样容易。但如果你知道怎么做,请在 SU 上回答相应问题:superuser.com/q/850749/373304
  • @gazillion 我不知道你是否在 Visual Studio 中进行开发,但 IIS Express 默认使用端口 80。
【解决方案2】:

我刚刚在 Windows 安装的 Xampp 上发现了与 Aliases 相同的问题。

解决403错误:

<Directory "C:/Your/Directory/With/No/Trailing/Slash">
   Require all granted
</Directory>

Alias /dev "C:/Your/Directory/With/No/Trailing/Slash"

默认的 Xampp 设置应该没问题。有些人遇到了在根目录上放置拒绝的问题,因此将目录标签翻转到:

<Directory "C:/Your/Directory/With/No/Trailing/Slash">
   Allow from all
   Require all granted
</Directory>

对此会有帮助,但当前版本的 Xampp(在撰写本文时为 v1.8.1)不需要它。

关于端口 80 的 op 问题,Xampp 包含一个方便的 Netstat 按钮,用于发现正在使用您的端口的内容。关闭它并解决冲突,我想它可能是 IIS 但不能确定。

【讨论】:

  • 感谢您和Require all granted,它成功了!
  • 之后请在隐身模式下测试
  • 我会把这个放在哪里?
【解决方案3】:

试试这个

sudo chmod -R 0777 /opt/lampp/htdocs/testproject

【讨论】:

  • 这是Windows环境。
  • 这个答案对我有帮助,即使它对提问者没有帮助
  • 在 Mac 上为我工作(这是我一直在寻找的)。谢谢!
  • 为什么会涨票?由于您刚刚创建了巨大的安全漏洞,因此这是一种解决问题的糟糕方法。
  • 不要这样做,这是一个重大的安全问题,因为您将写入和执行权限授予每个人!
【解决方案4】:

我在 Apache2.4 中使用 XAMPP,我遇到了同样的问题。我想保留默认的 xampp/htdocs 文件夹,能够从 locahost 访问它并让虚拟主机指向我的开发区域...

我的C:\xampp\apache\conf\extra\http-vhosts.conf 文件的完整内容如下...

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#

##NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ##ServerName or ##ServerAlias in any <VirtualHost> block.
#
##<VirtualHost *:80>
    ##ServerAdmin webmaster@dummy-host.example.com
    ##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com"
    ##ServerName dummy-host.example.com
    ##ServerAlias www.dummy-host.example.com
    ##ErrorLog "logs/dummy-host.example.com-error.log"
    ##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>

##<VirtualHost *:80>
    ##ServerAdmin webmaster@dummy-host2.example.com
    ##DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com"
    ##ServerName dummy-host2.example.com
    ##ErrorLog "logs/dummy-host2.example.com-error.log"
    ##CustomLog "logs/dummy-host2.example.com-access.log" common
##</VirtualHost>


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


<VirtualHost *:80>
    DocumentRoot "C:\nick\static"
    ServerName dev.middleweek.co.uk
    <Directory "C:\nick\static">
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

然后我像这样更新了我的C:\windows\System32\drivers\etc\hosts 文件...

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

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

127.0.0.1   dev.middleweek.co.uk
127.0.0.1       localhost

重新启动您的机器,打开 XAMPP 控制面板并启动 Apache。

现在在浏览器中打开您的自定义域,在上面的示例中,它将是 http://dev.middleweek.co.uk

希望对某人有所帮助!

如果您希望能够查看新虚拟主机下的目录列表,请在 C:\xampp\apache\conf\extra\http-vhosts.conf 中编辑您的 VirtualHost 块,以包含这样的“选项索引”...

<VirtualHost *:80>
    DocumentRoot "C:\nick\static"
    ServerName dev.middleweek.co.uk
    <Directory "C:\nick\static">
        Allow from all
        Require all granted
        Options Indexes
    </Directory>
</VirtualHost>

干杯, 尼克

【讨论】:

  • +1 只有在添加“要求所有授权”行后,我才设法克服“禁止访问”错误。更多相关内容写在What does Apache's “Require all granted” really do?serverfault.com/a/549559
【解决方案5】:

这个问题很老了,虽然你设法使它工作,但我觉得如果我澄清你在这里提出的一些观点会有所帮助。

首先关于目录名有空格。我一直在使用 apache2 配置文件,我发现,如果目录名称有空格,则将其括在双引号中,所有问题都会消失。 比如……

    NameVirtualHost     local.webapp.org
    <VirtualHost local.webapp.org:80>
        ServerAdmin admin@example.com
        DocumentRoot "E:/Project/my php webapp"
        ServerName local.webapp.org
    </VirtualHost>

注意 DocumentRoot 行的书写方式。

其次是关于禁止从 xampp 访问。我发现默认的 xampp 配置(..path to xampp/apache/httpd.conf)有一个如下所示的部分。

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

更改它并使其如下所示。保存文件 restart apache from xampp 即可解决问题。

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

【讨论】:

  • 最后一个选项(要求全部授予)对我有用。
【解决方案6】:

如果您通过 Bitnami 在 Xampp(Linux 上)上安装了模块并更改了 chown 设置,请确保 /opt/lampp/apps/&lt;app&gt;/htdocstmp 用户组为 daemon 以及所有其他同级文件和文件夹 chown编辑给您安装的用户,例如cd /opt/lampp/apps/&lt;app&gt;sudo chown -R root:root .,然后是sudo chown -R root:daemon htdocs tmp

【讨论】:

    【解决方案7】:

    Apache 2.4 虚拟主机破解

    1.在 http.conf 中指定端口,在“Listen”下面

    Listen 80
    Listen 4000
    Listen 7000
    Listen 9000
    
    1. 在 httpd-vhosts.conf 中

      <VirtualHost *:80>
      ServerAdmin webmaster@dummy-host2.example.com
      DocumentRoot "C:/Users/Vikas/Documents/NetBeansProjects/slider_website_hitesh/public_html"  
      ServerName hitesh_web.dev
      ErrorLog "logs/dummy-host2.example.com-error.log"
      CustomLog "logs/dummy-host2.example.com-access.log" common
      
      <Directory "C:/Users/Vikas/Documents/NetBeansProjects/slider_website_hitesh/public_html">
      Allow from all
      Require all granted
      </Directory>
      
      </VirtualHost>
      

      这是第二个虚拟主机

      <VirtualHost *:80>
      ServerAdmin webmaster@dummy-host2.example.com
      DocumentRoot "E:/dabkick_git/DabKickWebsite"
      ServerName  www.my_mobile.dev
      ErrorLog "logs/dummy-host2.example.com-error.log"
      CustomLog "logs/dummy-host2.example.com-access.log" common
      
      <Directory "E:/dabkick_git/DabKickWebsite">
       Allow from all
       Require all granted
       </Directory>
      </VirtualHost>
      
    2. 在windows os的hosts.ics文件中“C:\Windows\System32\drivers\etc\host.ics”

      127.0.0.1             localhost
      127.0.0.1             hitesh_web.dev
      127.0.0.1             www.my_mobile.dev
      127.0.0.1             demo.multisite.dev
      

    4.现在在浏览器中输入您的“域名”,它将 ping 在 documentRoot 路径中指定的特定文件夹

    5.如果您想在特定端口访问这些文件,请将 httpd-vhosts.conf 中的 80 替换为如下端口号并重新启动 apache

       <VirtualHost *:4000>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "C:/Users/Vikas/Documents/NetBeansProjects/slider_website_hitesh/public_html"
    ServerName hitesh_web.dev
    ErrorLog "logs/dummy-host2.example.com-error.log"
    CustomLog "logs/dummy-host2.example.com-access.log" common
    
    <Directory "C:/Users/Vikas/Documents/NetBeansProjects/slider_website_hitesh/public_html">
    Allow from all
    Require all granted
    </Directory>
    
    </VirtualHost>
    

    这是第二个虚拟主机

    <VirtualHost *:7000>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "E:/dabkick_git/DabKickWebsite"
    ServerName  www.dabkick_mobile.dev
    ErrorLog "logs/dummy-host2.example.com-error.log"
    CustomLog "logs/dummy-host2.example.com-access.log" common
    
    <Directory "E:/dabkick_git/DabKickWebsite">
    Allow from all
    Require all granted
    </Directory>
    </VirtualHost>
    

    注意:对于给定虚拟主机的端口号,您必须在浏览器中 ping,例如“http://hitesh_web.dev:4000/”或 “http://www.dabkick_mobile.dev:7000/

    6.完成所有这些更改后,您必须分别保存文件并重新启动 apache。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-02
      • 1970-01-01
      • 2022-10-09
      • 1970-01-01
      • 1970-01-01
      • 2017-01-14
      • 2015-08-01
      • 2019-12-21
      相关资源
      最近更新 更多