【问题标题】:You don't have permission to access / on this server您无权访问此服务器上的 /
【发布时间】:2013-06-30 19:28:15
【问题描述】:

我有 CentOS 6.1 服务器,并在上面安装了 apache 2.2.15。 现在,当我尝试从 IE (http:/// (=centos ip)) 的另一台电脑 (windows 7) 访问它时,我得到“您无权访问 / 对此服务器。”错误。我什至在“var/www/html”上创建了内容为“”的 phpinfo.php 文件,当我尝试在 IE 中使用“http://*/phpinfo.php”访问它时,我发现找不到错误。我该怎么办? 我的目录的 httpd.conf 是这样的:

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

【问题讨论】:

    标签: apache centos6


    【解决方案1】:

    对于 CentOS 8,您的 /etc/httpd/conf.d/awstats.conf 文件需要如下所示,并且您需要输入您的 IP 地址并重新启动您的 httpd 服务,除非您希望全世界都可以访问它!

    #
    # Directives to add to your Apache conf file to allow use of AWStats as a CGI.
    # Note that path "/usr/share/awstats/" must reflect your AWStats install path.
    #
    Alias /awstatsclasses "/usr/share/awstats/wwwroot/classes/"
    Alias /awstatscss "/usr/share/awstats/wwwroot/css/"
    Alias /awstatsicons "/usr/share/awstats/wwwroot/icon/"
    ScriptAlias /awstats/ "/usr/share/awstats/wwwroot/cgi-bin/"
    #
    # This is to permit URL access to scripts/files in AWStats directory.
    #
    <Directory "/usr/share/awstats/wwwroot">
        Options None
        AllowOverride None
        <IfModule mod_authz_core.c>
            # Apache 2.4
            <RequireAny>
               Require <Your IP Address here>
            </RequireAny>
        </IfModule>
        <IfModule !mod_authz_core.c>
            # Apache 2.2
            Allow from <Your IP address here>
            Allow from ::1
        </IfModule>
    </Directory>
    # Additional Perl modules
    <IfModule mod_env.c>
        SetEnv PERL5LIB /usr/share/awstats/lib:/usr/share/awstats/plugins
    </IfModule>
    

    请记住,如果您更改 IP 地址,您需要更新文件并重新启动 httpd 服务器。顺便说一句,您只需在谷歌上搜索“我的 ip”,您就可以从外部看到您的 ip 地址

    【讨论】:

      【解决方案2】:

      尝试编辑 httpd.conf

      <Directory "/usr/local/www/apache24/cgi-bin">
        Options Indexes FollowSymLinks Includes ExecCGI
        Require all granted
      </Directory> 
      

      【讨论】:

      • 你不应该只是复制粘贴,还要解释你做了什么。
      【解决方案3】:

      在 /etc/httpd/conf/httpd.conf 中设置所需的所有权限

      【讨论】:

        【解决方案4】:

        如果您将 SELinux 设置为许可模式(命令 setenforce 0)并且它可以工作(对我有用),那么您可以运行 restorecon (sudo restorecon -Rv /var/www/html/),它为 Apache 目录中的文件永久设置正确的上下文,因为 setenforce 是临时的. Apache 的上下文是 httpd_sys_content_t,您可以运行命令 ls -Z /var/www/html/ 来验证它,该命令输出如下内容:

        -rwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 index.html

        如果文件没有正确的上下文,显示如下:

        drwxr-xr-x. root root unconfined_u:object_r:user_home_t:s0 tests

        希望对你有帮助。

        PD:对不起我的英语

        【讨论】:

          【解决方案5】:

          使用以下命令将 SELinux 设置为许可模式:

          setenforce 0;
          

          【讨论】:

            【解决方案6】:

            检查 httpd.conf 中的 apache 用户和组设置。它应该默认为 AMI/RedHat 上的 apache 或 Debian 上的 www-data。

            grep '^Group\|^User' /etc/httpd/conf/httpd.conf
            

            然后将apache用户添加到你站点根目录的组设置中。

            sudo usermod -a -G <your-site-root-dir-group> apache
            

            【讨论】:

              【解决方案7】:

              右键单击您的 www 文件夹,然后单击属性。导航到权限并将所有更改为读取和写入,然后单击“对随附文件应用权限”,您就完成了! 也许为时已晚,但这肯定会帮助其他人

              【讨论】:

                【解决方案8】:

                尝试使用以下内容: chmod +rx /home/*

                【讨论】:

                  【解决方案9】:

                  编辑/etc/httpd/conf/httpd.conf 中的httpd.conf 文件。添加以下代码。

                  <Directory "/">
                  #Options FollowSymLinks
                  Options Indexes FollowSymLinks Includes ExecCGI
                  AllowOverride None
                  Allow from all
                  </Directory>
                  
                  <Directory "/home/">
                   #Options FollowSymLinks
                   Options Indexes FollowSymLinks Includes ExecCGI
                   AllowOverride None
                   Allow from all
                  </Directory>
                  

                  在行号之后。 555(在我的情况下)。检查文件权限并重新启动服务器。

                  service httpd restart   
                  

                  现在,它可以工作了。你仍然面临同样的问题,禁用/etc/selinux/config 中的seLinux 更改SELINUX=disabled 并如上所述重新启动服务器并尝试它。

                  希望对你有帮助

                  【讨论】:

                  • 禁用 selinux 为我修复了它
                  • 一个危险的解决方案Protect Server Files by Default
                  • 如果不禁用 selinux,我无法使其工作。这对我的设置是绝对必要的。
                  • 禁用 selinux 也为我修复了它
                  【解决方案10】:

                  首先检查 apache 是否正在运行。 service httpd restart 重启

                  CentOS 6 带有激活的 SELinux,因此,要么更改策略,要么通过编辑 /etc/sysconfig/selinux 设置 SELINUX=disabled 禁用它。然后重启

                  然后在本地(从 centos)检查 apache 是否正常工作。

                  【讨论】:

                  • 我没有本地访问centos,但我做了SELINUX的事情,它仍然是同样的错误!
                  • 你有没有试过从centos控制台做wget localhost然后用文本编辑器检查响应?
                  • 我做到了,它工作正常,本地主机(index.html)的内容等于服务器中的一个。
                  • 我认为你可以使用setsebool -P httpd_enable_homedirs true 而不是禁用 SELinux
                  【解决方案11】:

                  检查 /var/www/html 的文件权限和 Apache conf 中的 ALLOW 指令

                  确保所有文件都可以被网络服务器读取,并且允许指令类似于

                   <Directory "/var/www/html">
                      Order allow,deny
                      Allow from all
                    </Directory>
                  

                  如果你能看到文件,那么考虑对指令进行更严格的排序

                  【讨论】:

                  • 选项索引 FollowSymLinks AllowOverride None Order allow,deny Allow from all
                  • 它是否在本地工作 - 如果您在机器本身上定位 localhost 如果只有 cli 尝试使用 curl
                  • 我没有本地访问 centos 服务器
                  • 嗯,好的 - 那么内部防火墙的问题是你在 iptables 中打开了 80 吗?
                  • 我在 /etc/sysconfig/iptables 中添加了“-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT”这一行,然后重新启动了 iptables .它重新启动正常,但尝试从外部访问时仍然出现相同的 FORBIDDEN 错误。
                  【解决方案12】:

                  在根目录中创建 index.htmlindex.php 文件(在您的情况下 - /var/www/html,如 @jabaldonedo 所述)

                  【讨论】:

                  • centos 使用 /var/www/html 作为网页内容的文件夹
                  • 检查该文件的权限。
                  • 权限应该是什么?
                  • 尝试所有 6-es,或将 apache 设为所有者。
                  • 我成为了 apache 的所有者!还是不行,而且所有的权限也没用!!
                  猜你喜欢
                  • 2019-02-22
                  • 2017-05-04
                  • 2015-10-06
                  • 2015-10-07
                  • 2012-12-08
                  • 2017-05-30
                  • 2015-12-24
                  相关资源
                  最近更新 更多