【问题标题】:Forbidden: You don't have permission to access / on this server (centos 7)禁止:您无权访问此服务器上的 / (centos 7)
【发布时间】:2020-04-16 00:46:35
【问题描述】:

我在主机上安装了httpd,修改了httpd.conf文件如下

ServerRoot "/etc/httpd"

Listen 80


Include conf.modules.d/*.conf


User apache
Group apache

ServerAdmin root@localhost

<Directory />
    AllowOverride none
    Require all granted
</Directory>
DocumentRoot "/home/admin/domains/morabi.app/public_html"

<Directory "/var/www">
    AllowOverride None
    Require all granted
</Directory>

<Directory "/var/www/html">
    Options Indexes FollowSymLinks

    AllowOverride None

    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<Files ".ht*">
    Require all denied
</Files>

当我在浏览器中加载我的 IP 地址时,它显示“禁止 您无权访问此服务器上的 /。”错误。并且 /home/admin/domains/morabi.app 权限为 755 还加载了文件,但我的 ip http://x.x.x.x/ 有禁止错误

【问题讨论】:

  • 我的回答现在有效吗?

标签: apache permissions centos httpd.conf httpforbiddenhandler


【解决方案1】:

您需要在其中添加以下内容,

<Directory "/home/admin/domains/morabi.app/public_html">
# Learn more about this at https://httpd.apache.org/docs/2.4/mod/core.html#options
Options Indexes FollowSymLinks

# Learn more about this at https://httpd.apache.org/docs/2.4/mod/core.html#allowoverride
AllowOverride All

# The solution for your error, allows your files to be served, learn more about this at https://httpd.apache.org/docs/2.4/howto/access.html
Require all granted
</Directory>

然后重新启动 Apache。

这是很多人忘记的,有些人不知道的。请注意这一点。

编辑:
在目录配置中添加了单词public_html

另一个提示

在运行这些命令之前进行备份,如果文件发生任何问题,我概不负责。

尝试通过在终端内的 morabi.app 中运行 ls -la 来检查文件夹 public_html 的所有者,如果它不是您的用户或 apache,请尝试在目录 morabi.app 中运行此命令:

确保您以您使用的主要用户身份运行它,我建议您不要将其更改为 root。

chown $USER:$USER public_html -R

上述命令将更改文件夹的所有者和其中的文件。如果将所有者更改为运行命令的用户不起作用,请将 $USER 更改为 apache,但请始终按照我上面所说的进行备份。

【讨论】:

  • 也尝试删除以# 符号开头的行。
  • 我认为我以前错了,但按照我上面所说的尝试这个。
猜你喜欢
  • 1970-01-01
  • 2019-09-11
  • 2014-06-07
  • 2018-08-06
  • 2013-05-15
  • 2016-05-06
  • 2017-08-10
  • 2014-02-28
相关资源
最近更新 更多