Linux中访问Apache报403错误处理方法

1、先说本地环境,脱离基础环境的解决策略都是耍流氓

(1)Linux:CentOS7.5

(2)Apache: Apache/2.4.6 (CentOS)

(3)Apache的安装路径在 /usr/local/httpd2.4

2、出现错误

按照正常的流程解压Apache包并完成配置,正常启动,启动后,输入访问URL:http://IP:端口/,很不幸页面出现403Forbidden错误。You don't have permission to access / on this server。

3、解决措施

(1) 首先是修改/home/project/soft/apache/conf/httpd.conf。找到<Directory />,并将里面的内容修改如下:

<Directory />

AllowOverride all

Require all granted

</Directory>

(2)此时如果重启Apache服务,发现仍然是无法访问,但是页面报错增加了一行内容“Server unable to read htaccess file, denying access to be safe”。此时要会去查看Apache的日志。(Apache安装路径下log/error_log),发现里面有报错信息:Fri Sep 28 16:33:22.661903 2018] [core:crit] [pid 16685:tid 139887686231808] (13)Permission denied: [client 172.16.40.224:50470] AH00529: /home/project/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/home/project/' is executable。按照报错提示,在/home/project下建立文件.htaccess,并在文件中输入以下内容:

Order allow,deny

Allow from all

Require all granted

保存并退出。

(3)此时可以直接重启Apache并尝试方式是否正常,如果不正常,再执行以下步骤:

chmod 755 /home/project

(4)上述步骤全部执行完后,应该可以正常访问了。