干净的 CentOS 安装上的 Apache Forbidden 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1645433/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 18:20:28  来源:igfitidea点击:

Apache Forbidden error on clean CentOS install

apachecentoshttp-status-code-403

提问by Peter Parker

I have a clean copy of CentOS.

我有一个干净的 CentOS 副本。

Just installed Apache, PHP and MySQL. Everything works like a charm.

刚刚安装了 Apache、PHP 和 MySQL。一切都像一个魅力。

Except for I created a new user, let's call it 'demo'.

除了我创建了一个新用户,我们称之为“演示”。

I created a new virtual directory in httpd.conf and pointed it to '/home/demo/www'. I created an empty index.html under '/home/demo/www'.

我在 httpd.conf 中创建了一个新的虚拟目录并将其指向“/home/demo/www”。我在“/home/demo/www”下创建了一个空的 index.html。

Apache is running under user 'apache' and group 'apache'.

Apache 在用户 'apache' 和组 'apache' 下运行。

Maybe user 'apache' does not have access to user 'demo's file, that's why I get the Forbidden problem?

也许用户 'apache' 无权访问用户 'demo' 的文件,这就是我遇到 Forbidden 问题的原因?

Do you have any ideas how to solve this problem?

你有什么想法如何解决这个问题吗?

Thanks,

谢谢,

James

詹姆士

回答by

The solution was to give a 'chmod 755' to '/home/demo'.

解决方案是给“/home/demo”一个“chmod 755”。

回答by Peter Parker

Without seeing your config files It is difficult to find the right spot, however Apache will not show 403 if he does not have permissions on files.

没有看到您的配置文件很难找到正确的位置,但是如果 Apache 没有文件权限,则不会显示 403。

403 means the client(your browser) has not a permission to view the content

403 表示客户端(您的浏览器)没有查看内容的权限

I think you have a trailing slashproblem. Just try this code:

我认为你有一个尾随斜线问题。试试这个代码:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /home/demo/www/
    ServerName DemoSite
    ErrorLog logs/sb-error_log
    CustomLog logs/sb-access_log common
</VirtualHost>

回答by Gustavo Lozano

You need to add:

您需要添加:

<Directory "/home/demo/www">
   # Allow open access:
   Require all granted
/Directory>

To your Virtual Host definition.

到您的虚拟主机定义。