![](/img/trans.png)
[英]403 - Forbidden with Apache and Django on Windows with mod_wsgi
[英]403 Forbidden error with Django and mod_wsgi
我在主目錄中創建了 Django 項目,因此它位於主目錄中。
設置
Django Verison : 1.5.1
Python Version : 2.7.5
mod_wsgi Version: 3.4
Home Directory : /home/aettool
/home/aettool/aet/apache/django.wsgi
內容
import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'aet.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
httpd.conf
WSGIScriptAlias / /home/aettool/aet/apache/django.wsgi
<Directory /home/aettool/aet/apache>
Order deny,allow
Allow from all
</Directory>
error_log
錯誤
[Sun Jul 21 02:01:30.923364 2013] [authz_core:error] [pid 21540:tid 1193011520] [client 10.20.17.184:51340] AH01630: client denied by server configuration: /home/aettool/aet/apache/django.wsgi
urls.py
內容
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
)
/home/aettool/aet : 775
權限/home/aettool/aet : 775
/home/aettool/aet/apache : 755
權限/home/aettool/aet/apache : 755
django.wsgi file : 664
權限django.wsgi file : 664
我在瀏覽器上收到錯誤403 Forbidden
You don't have permission to access / on this server.
請幫我進行配置。
編輯
現在我正在通過改變前進
<Directory />
AllowOverride none
Require all denied
</Directory>
到
<Directory />
Order deny,allow
Allow from all
</Directory>
所以,這肯定與httpd.conf
文件配置有關,但我擔心的是我只在該文件中添加了 5 行並且無法弄清楚出了什么問題。
顯然,這是一個與 Apache 2.4 及更早版本相關的問題。 您需要在 apache 配置中替換:
Allow from all
和
Require all granted
在<Files wsgi.py>
部分
您可以使用以下內容:
<Directory /home/aettool/aet/apache>
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
</Directory>
這已在 Django 票 19319 中報告:
https://code.djangoproject.com/ticket/19319
您的 Apache 配置現在需要您的文件wsgi.py
的以下wsgi.py
。
<Directory /path/to/your/wsgi-script>
<Files wsgi.py>
Order deny,allow
Allow from all
Require all granted
</Files>
</Directory>
還有一個問題:
檢查您的 httpd.conf 文件以獲取以下配置:
<IfModule mime_module>
AddHandler cgi-script .cgi .pl .py
</IfModule>
這將導致錯誤。
.py 不得配置為 CGI 腳本
Linux 系統通常不允許其他用戶讀取主目錄內部,並且由於 Apache 以 root 身份運行,因此 mod_wsgi 將無法訪問主目錄內部。 嘗試:
sudo chmod 755 /home/<username>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.