2013-07-20 41 views
29

Tôi đã tạo dự án Django trong thư mục chính để nó nằm trong thư mục chính.403 Lỗi bị cấm với Django và mod_wsgi

Cài đặt

Django Verison : 1.5.1 
Python Version : 2.7.5 
mod_wsgi Version: 3.4 
Home Directory : /home/aettool 

Nội dung /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() 

contect của httpd.conf

WSGIScriptAlias//home/aettool/aet/apache/django.wsgi 

<Directory /home/aettool/aet/apache> 
Order deny,allow 
Allow from all 
</Directory> 

Lỗi trong 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 

Nội dung 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)), 
) 

Permissions of /home/aettool/aet : 775

Permissions of /home/aettool/aet/apache : 755

Permissions of django.wsgi file : 664

Tôi nhận được lỗi trên trình duyệt 403 ForbiddenYou don't have permission to access/on this server.

Xin hãy giúp tôi ra với cấu hình.

EDIT

Để bây giờ tôi đang di chuyển về phía trước bằng cách thay đổi

<Directory /> 
    AllowOverride none 
    Require all denied 
</Directory> 

để

<Directory /> 
    Order deny,allow 
    Allow from all 
</Directory> 

Vì vậy, điều này có chắc chắn cái gì để làm với httpd.conf cấu hình tập tin, nhưng lo lắng của tôi là tôi chỉ thêm 5 dòng trong tệp đó và không thể tìm ra điều gì sai.

+0

Hãy chỉ cho chúng ta của bạn 'urls.py' –

+0

thêm trong câu hỏi – g4ur4v

+1

Dupe: http://stackoverflow.com/questions/4807176/apache-mod-wsgi-error-forbidden-you-dont-have -permission-to-access-on-this-s? rq = 1 –

Trả lời

39

Rõ ràng đây là sự cố liên quan đến phiên bản Apache 2.4 trở lên. Bạn cần phải thay thế trong cấu hình apache của bạn:

Allow from all 

với

Require all granted 

trong phần <Files wsgi.py>

+2

Điều đó khiến tôi phát điên –

16

Bạn có thể sử dụng như sau:

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

Trên các phiên bản apache cũ, nó sẽ là cần thiết để kích hoạt mod "phiên bản" với '' 'sudo a2enmod version''' – azmeuk

2

Có một khác gotcha:

Kiểm tra httpd của bạn.tệp conf cho cấu hình sau:

<IfModule mime_module> 
     AddHandler cgi-script .cgi .pl .py 
</IfModule> 

Điều này sẽ gây ra lỗi.

py PHẢI KHÔNG được cấu hình như một kịch bản CGI

+0

Điều này là dành cho tôi. Cảm ơn. –

4

này đã được báo cáo trong 19.319 vé Django:

https://code.djangoproject.com/ticket/19319

cấu hình Apache của bạn bây giờ cần những điều sau đây cho tập tin của bạn wsgi.py.

<Directory /path/to/your/wsgi-script> 
<Files wsgi.py> 
    Order deny,allow 
    Allow from all 
    Require all granted 
</Files> 
</Directory> 
+1

Điều này có hiệu quả, nhưng với không cho wsgi-script – eli

Các vấn đề liên quan