你没有权限访问该服务器上的 / 目录。

15
我有一个CentOS 6.1服务器,并在上面安装了apache 2.2.15。 现在,当我尝试从另一台PC(Windows 7)的IE中访问它(http:///(= centos ip))时,我得到了“您没有权限访问此服务器上的/”错误。 我甚至在“var / www / html”上创建了内容为“” 的phpinfo.php文件,当我尝试使用“http:// */ phpinfo.php”在IE中访问它时,我得到了找不到的错误。 我该怎么办? 我的httpd.conf目录设置如下:
<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
12个回答

25
编辑位于/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更改并像上面提到的那样重新启动服务器,然后再试一次。
希望这可以帮助你。

5
禁用 SELinux 对我来说解决了这个问题。 - simotek
一种危险的解决方案 默认保护服务器文件 - RiggsFolly
2
没有禁用selinux,我就无法使其正常工作。这对我的设置来说是绝对必要的。 - Somum
1
禁用selinux对我也起了作用。 - Fokwa Best

11

使用以下命令将 SELinux 设置为宽容模式:

setenforce 0;

3

请检查/var/www/html目录下的文件权限以及在你的apache配置文件中是否设置了ALLOW指令。

确保所有文件可被web服务器读取,而且ALLOW指令应该如下所示:

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

如果您可以看到文件,请考虑将指令排序更加严格。

<Directory "/var/www/html"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory><目录 "/var/www/html"> 选项 索引 跟随符号链接 允许覆盖无 排序 允许,拒绝 允许所有人 </目录> - Ehphan
仅在本地运行 - 如果针对本机的 localhost 进行目标 如果仅使用 CLI,请尝试使用 curl - Shaun Hare
我没有本地访问CentOS服务器的权限。 - Ehphan
啊,好的 - 那么内部防火墙的问题是有在iptables中打开80端口吗? - Shaun Hare
我在/etc/sysconfig/iptables中添加了一行“-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT”,然后重新启动了iptables。它成功重启,但是从外部访问时仍然出现相同的FORBIDDEN错误。 - Ehphan

2

首先检查Apache是否正在运行。service httpd restart用于重新启动。

CentOS 6默认启用SELinux,因此要么更改策略,要么通过编辑/etc/sysconfig/selinux将其禁用,设置SELINUX=disabled。然后重新启动。

然后从CentOS本地检查Apache是否正常工作。


我没有本地访问CentOS,但我已经尝试了SELINUX的方法,但仍然出现相同的错误!! - Ehphan
你尝试过从CentOS控制台执行 wget localhost,然后用文本编辑器检查响应吗? - jabaldonedo
我已经这样做了,它可以正常工作,本地主机的内容(index.html)与服务器上的相同。 - Ehphan
1
我认为你可以使用 setsebool -P httpd_enable_homedirs true 来启用SELinux,而不是禁用它。 - nyxz

2
尝试使用以下命令: chmod +rx /home/*

1
如果您将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

希望这可以帮助您。

附注:请原谅我的英语


0

请检查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

0
尝试编辑httpd.conf文件。
<Directory "/usr/local/www/apache24/cgi-bin">
  Options Indexes FollowSymLinks Includes ExecCGI
  Require all granted
</Directory> 

1
你不应该只是复制粘贴,还应该解释你做了什么。 - mrkernelpanic

0

对于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地址在外部的样子。


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

1
CentOS使用/var/www/html作为Web内容的文件夹。 - jabaldonedo
检查该文件的权限。 - David Jashi
权限应该是什么? - Ehphan
尝试使用所有6-es,或将“apache”设置为所有者。 - David Jashi
1
我把Apache的所有者改成了自己!但是它仍然无法正常工作,而且所有权限也都不起作用!! - Ehphan
我也遇到了同样的问题,请帮帮我。 - user1181940

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