首頁  >  文章  >  運維  >  apache 403 forbidden怎麼解決

apache 403 forbidden怎麼解決

藏色散人
藏色散人原創
2019-12-16 14:34:174214瀏覽

apache 403 forbidden怎麼解決

apache 403 forbidden怎麼解決?

apache httpd伺服器403 forbidden的問題

一、問題描述

在apache2的httpd設定中,很多情況都會出現403。

剛好安裝好httpd服務,當然是不會有403的問題了。主要是修改了一些配置後出現,問題描述如下:

修改了DocumentRoot目錄指向後,網站出現403錯誤。

設定了虛擬主機目錄也可能導致403。

apache的httpd服務成功啟動,看起來都很正常,卻沒有權限存取

日誌出現: access to / denied (filesystem path '/srv/lxyproject/wsgi/django.wsgi ') because search permissions are missing on a component of the path

設置虛擬目錄後,錯誤日誌出現:client denied by server configuration: /srv/lxyproject/wsgi/django.wsgi

二、分析問題及方案

下面一步步解決問題時注意錯誤日誌內容。 ok,開始。

1、httpd.conf中目錄設定檔

如果顯示更改了DocumentRoot,例如改為 "/usr/local/site/test" 。 site目錄和test目錄是使用mkdir建立的,然後在test目錄下放置一個index.html。這種情況應該要查看httpd.conf中配置。

你的055616abb69b52339271a1cffd27ee59一定要和DocumentRoot一致,因為這段Directory是apache對該目錄訪問權限的設置,只有設置正確的目錄,DocumentRoot才會生效。

<Directory "/usr/local/site/test">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn&#39;t give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks
    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None
    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

2、目錄存取權限

第一步配置正確還是出現403,檢查目錄設定055616abb69b52339271a1cffd27ee59中是否有Deny from all。有則所有訪問都會被拒絕,當然403了。

可以設定為Allow from all或是Require all granted來處理。

不要修改7d50add1c973852b0a9343a1c5b78333根目錄中Deny from all。

3、目錄權限

如果至此還是403,可能是網站目錄的權限問題。

apache要求目錄具有執行權限,也就是x,要注意的是,你的目錄樹都應該擁有這些權限。

假如你的目錄是/usr/local/site/test,那麼要保證/usr,/usr/local,/usr/local/site,/usr/local/site/test這四個層級的目錄都是755權限。

#chmod 755 /usr/local/site
#chmod 755 /usr/local/site/test

我犯過一個錯誤就是只設定了最後一級目錄權限,沒有設定上級目錄權限,導致403。

4、虛擬目錄

【這個問題我沒遇過,因為我沒這樣寫過,網路資料這麼寫,可作為參考】

如果設定的是虛擬目錄,那麼你需要在httpd.conf中定義一個虛擬目錄,而且像極瞭如下的片段:

Alias /folder "/usr/local/folder"                       
<Directory "/usr/local/folder">                         
    Options FollowSymLinks                            
    AllowOverride None                              
    Order deny,allow                               
    Deny from all                                 
    Allow from 127.0.0.1 192.168.1.1                       
</Directory>

如果是這一種情況,而且你寫得類似我上面的程式碼,三處folder都是一樣一樣的,那絕對會是403!怎麼解決呢,就是把跟在Alias後面斜槓後面的那串改了,改成什麼,不要和虛擬目錄的資料夾同名就好,然後我就可以用改過後的虛擬目錄訪問了,當然,改資料夾也行,只要你不怕麻煩,只要Alias後面的虛擬目錄定義字元(紅色)和實際資料夾名稱(黑色)不相同就OK。

5、selinux的問題

如果還是403,那就是selinux在作怪了,於是,你可以把你的目錄進行一下selinux權限設定。

今天我遇到的就是這個問題了。

#chcon -R -t httpd_sys_content_t /usr/local/site
#chcon -R -t httpd_sys_content_t /usr/local/site/test

網路資料說不過,這一步大多不會發生。但我的問題確實是,可能跟系統有關,具體原理還不是很懂。

6、wsgi的問題

我的虛擬主機配置為:

<VirtualHost *:80>
WSGIScriptAlias / /srv/lxyproject/wsgi/django.wsgi
Alias /static/ /srv/lxyproject/collectedstatic/
ServerName 10.1.101.31
#ServerName example.com
#ServerAlias www.example.com
<Directory /srv/lxyproject/collectedstatic>
  Options Indexes  FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
<Directory /srv/lxyproject/wsgi/>
    Allow from all
</Directory>
ErrorLog   /etc/httpd/logs/lxyproject.error.log
LogLevel warn
</VirtualHost>

我訪問

log報錯:

client denied by server configuration: /srv/lxyproject/wsgi/django.wsgi

解決辦法:

修改a84c9d6c966af598e4332f18bd310657中Allow from all為:Require all granted。

這個問題是因為版本的原因,

我的httpd版本為:

[root@yl-web conf.d]# rpm -qa |grep httpd
httpd-devel-2.4.6-31.el7.centos.x86_64
httpd-tools-2.4.6-31.el7.centos.x86_64
httpd-2.4.6-31.el7.centos.x86_64

而2.3以下版本用Allow from all,2.3以上版本為Require all granted 。

<Directory /home/aettool/aet/apache>
  <IfVersion < 2.3 >
   Order allow,deny
   Allow from all
  </IfVersion>
  <IfVersion >= 2.3>
   Require all granted
  </IfVersion>
</Directory>

以上是apache 403 forbidden怎麼解決的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn