centos64i386下apache 403没有权限访问。

由于想看看一些html文档,放到centos的httpd服务下,但是一直提示403没有权限,恶心死我了。

index.html文件无法访问,但是改名成为 index2.html就可以访问呢,真是气死人了。

检查权限与用户组设置

================

由于 sudo service httpd restart 需要root权限,但是/etc/httpd/conf/httpd.conf里面

[root@arcsdexen1 html]# pwd
/var/www/html
[root@arcsdexen1 html]# ll
总用量 8
drwxr-xr-x. 10 root root 4096 5月  31 18:15 Help
-rwxr-xr-x.  1 root root    7 5月  31 17:46 index2.html
[root@arcsdexen1 html]# ll ..
总用量 16
drwxr-xr-x. 2 root root 4096 2月  22 19:18 cgi-bin
drwxr-xr-x. 3 root root 4096 5月  29 16:12 error
drwxr-xr-x. 3 root root 4096 5月  31 18:15 html
drwxr-xr-x. 3 root root 4096 5月  29 16:13 icons
[root@arcsdexen1 html]# 

我修改过用户组为 apache:apache ,权限改成 -rw-r--r-- 644 ,-rwxr-xr-x 755 -rwxrwxrwx 777 都试过了,都是没有权限,狗日的apache,httpd,我root都777 了哪里没权限了,莫名其妙。

检查httpd.conf配置

==================

先把 /etc/httpd/conf.d/welcome.conf 关闭掉,省的访问主目录没有index.html 就跳转到默认页面。

vim /etc/httpd/conf.d/welcome.conf 

# 
# This configuration file enables the default "Welcome"
# page if there is no default index page present for
# the root URL.  To disable the Welcome page, comment
# out all the lines below.
#
#<LocationMatch "^/+$">
#    Options -Indexes
#    ErrorDocument 403 /error/noindex.html
#</LocationMatch>

注释掉,再修改下显示indexed 显示文件索引(如果没有index.html 等默认网页文件的话)将主目录的index.html重命名 index2.html,目的为了 indexed 显示文件索引。

httpd.conf 包含默认注释

发现 子目录都无法访问。好吧搜索下

通过apache 子目录 403 找到这个文章 

http://hi.baidu.com/c4bbage/item/b6c4ef244bb9791e097508ac

apache web子目录403

在Apache下访问cunlide的网站,网站的原始内容可以访问,但是有余URL Rewrite,不太会直接访问到子目录的内容。
但是,当在根目录下添加一个子目录加一些html的时候,访问就会报403错误。
其实Google还是一个好东西,大概就是由于Selinux引起的。所以,只要设置一下配置就好了:

chcon -R -t httpd_user_content_t [目录名]  

看了后,我气死了,最讨厌的就是 告诉你你错了,但是你就是找不到哪里错误,它也不给你任何提示。selinux我才不学呢,直接关闭。

把SELINUX关闭掉,不重启使用一条命令setenforce 就可以了。

#vim /etc/selinux/config



# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted



#setenforce  0
#getenforce
Permissive

service httpd restart

原文地址:https://www.cnblogs.com/ayanmw/p/3110930.html