Linux http服务禁止访问

CentOS8 启动httpd服务之后,http://localhost显示forbidden,You have no permission to access / on this server…

学习鸟哥的Linux私房菜,第22章,22.3.7基础服务管理,以Apache为例。

环境:CentOS8,
httpd版本:Apache/2.4.37 (centos)

在安装好并启动httpd服务之后,浏览器输入http://localhost显示 forbidden,You have no permission to access / on this server…,网上的说法很多
1、把配置文件/etc/httpd/conf/httpd.conf中的Require all denied改为Require all required.但是我的配置文件是没有问题的。注意Apache 2.2和2.4配置文件的语法是不同的,详见Apache官方文档

2、 目录权限问题,将文档根目录/var/www/html的权限改为755 chmod 755 /var/www/html,我的还是没有问题。注意如果你的Linux开启了selinux,还需要配置目录权限符合selinux,首先检查该目录:

ll -dZ /var/www/html

如果该目录的模式类别不是httpd_user_content_t,则需要将其修改为httpd_user_content_t:

chcon -R -t  httpd_user_content_t /var/www/html

或者使用setenforce=0暂时关闭selinux安全文本检查。
我的依然没有问题。

3、防火墙问题,需要开放80端口:

firewall-cmd --add-port=80/tcp --permanent

注意开启之后需要重载防火墙,firewall-cmd --reload.
我的还是没有问题。
之后突然想到去看一下log文件,找到了/etc/httpd/logs/error_log,找到这样的信息:

[Tue Jan 07 21:20:02.452934 2020] [autoindex:error] [pid 1078:tid 139827569248000] [client ::1:38944] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html) found, and server-generated directory index forbidden by Options directive

百度了一下,说的是根目录里面没有index.html 或者 index.php,可以添加设置:Options FollowSymLinks Indexes,然鹅,我的配置文件中也是有的。。。心累。。。
后来又认真看了一下日志,他的提示是autoindex:error,就去找找有没有一个文件是autoindex,果然找到了,继续百度,网上关于autoindex说的是没有开启目录浏览,把Options -Indexes FollowSymLinks中的-去掉就是可以开启目录浏览,最后果然可以浏览目录了。

感觉排错最重要的还是查看log吧。

发布了16 篇原创文章 · 获赞 0 · 访问量 350

猜你喜欢

转载自blog.csdn.net/qq_41922018/article/details/103908494