apache 访问出现403 Forbidden

在linux虚拟机的apache上新增一个虚拟目录/var/wordpress,想把理论网挂上去。

在配置文件httpd.conf中,把”Include conf/extra/httpd-vhosts.conf”这句前面的注释去掉,引用httpd-vhosts.conf配置文件。并且在Listion 80 下面新增一行Listion 8080。

然后再打开conf/extra/httpd-vhosts.conf,注释其中配置。自己手动写一个

<virtualHost *:8080>
ServerAdmin cblx@sohu.com
DocumentRoot "/var/wordpress"
Servername localhost

<Directory "/var/wordpress">
Options Indexes FollowSymLinks
        AllowOverride None
        order allow,deny
        Allow from all
DirectoryIndex index.php </Directory> </VirtualHost>

 重启apache服务,提示:

Forbidden
You don't have permission to access / on this server.

 浏览百度,都是要将

Deny from all

 改为

Allow from all

 可我不存在这个问题呀!

想到selinux,用getenforce 看,发现selinux是关着的。

最后,用http://ifalone.me/569.html这篇文章的方法予以解决。

于是查看apache的主配置文件,找到了以下限制访问的内容:

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
   AllowOverride none
   Require all denied
</Directory>

 以上内容限制用户访问系统根目录,这应该是apache的默认安全设置,但是也限制了我们的设置目录地址,于是将上述内容修改成:

<Directory />
    AllowOverride none
#   Require all denied
    Options FollowSymLinks
    Order deny,allow
    allow from all
</Directory>

 问题解决!!

原文地址:https://www.cnblogs.com/cblx/p/4189493.html