阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Apache2.4.*提示Forbidden You don’t have permission to access / on this server.

142次阅读
没有评论

共计 1757 个字符,预计需要花费 5 分钟才能阅读完成。

前言:

继前面 Ubuntu Server 14.04 LTS 下搭建 LAMP 环境图文详解之后 (见 http://www.linuxidc.com/Linux/2016-12/138758.htm),在配置一个虚拟主机时,这中间却遇见了一个问题,这里需要描述做一下笔记,刚刚安装的是 Ubuntu server,apt-get 下来的 apache 的版本是 2.4.7,之前一直用的是 apache2.2 的,期间遇见过 403 错误,只是问题处理的方式方法有些不一样,于是这里就一时没有找到头绪。

403:没有权限访问

不说废话直接找主题:

首先我们来回顾一下 apache2.2 的配置

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

server 默认 000-default.conf 配置文件,在 copy 的文件后没有发现 directory 这一部分,搜也没有搜出想要的答案,在 apache 官网上发现了这一变化。

In this example, all requests are denied.
2.2 configuration:
Order deny,allow
Deny from all

2.4 configuration:
Require all denied

In this example, all requests are allowed.
2.2 configuration:
Order allow,deny
Allow from all

2.4 configuration:
Require all granted

In the following example, all hosts in the example.org domain are allowed access; all other hosts are denied access.
2.2 configuration:
Order Deny,Allow
Deny from all
Allow from example.org

2.4 configuration:
Require host example.org

看到上面的配置文件应该可以看出一部分问题,配置文件的写法有些变化了,需要将配置文件修改为 Require all granted。

官网解释:http://httpd.apache.org/docs/2.4/upgrading.html

虚拟主机配置步骤:

配置一个 ServerName:demo.pushself.com

① 复制一份默认的配置文件

cd /etc/apache2/sites-available
sudo cp 000-default.conf demo.conf
sudo vim demo.conf

ServerName demo.pushself.com #新增一句 ServerName
ServerAdmin webmaster@localhost
DocumentRoot /wwwroot/demo #修改为你的项目路径
<Directory /wwwroot/demo> #新增权限配置不同于 2.2
Require all granted
</Directory>
sudo ln -s /etc/apache2/sites-available/demo.conf /etc/apache2/sites-enabled/demo.conf
sudo service apache2 restart

②我是远程连接的 server,所以我需要修改一下客户端的 hosts 文件,添加一句模拟 DNS

192.168.25.107 demo.pushself.com #IP 是我的 server 地址

注意:如果上述配置后还是还是会 403 Forbidden,原因是没有 index 文件,为了解决这个问题,我们可以再配置文件添加一句,新增后记得重启 apache

<Directory /wwwroot/demo> #新增权限配置不同于 2.2
Options FollowSymLinks Indexes
Require all granted
</Directory>

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-12/138759.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计1757字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中