server下apache2.4.*虛擬主機配置Forbidden You don't have permission to access / on this server.


前言:

  繼前面兩節筆記之后,在配置一個虛擬主機時,這中間卻遇見了一個問題,這里需要描述做一下筆記,剛剛安裝的是Ubuntu server,apt-get下來的apache的版本是2.4.7,之前一直用的是apache2.2的,期間遇見過403錯誤,只是問題處理的方式方法有些不一樣,於是這里就一時沒有找到頭緒。本文原創博客地址:http://www.cnblogs.com/unofficial官網地址:www.pushself.com)

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本文原創博客地址:http://www.cnblogs.com/unofficial官網地址:www.pushself.com)

虛擬主機配置步驟:

配置一個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.cnblogs.com/unofficial官網地址:www.pushself.com)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM