Python 403 Django 和 mod_wsgi 的禁止错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17766595/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
403 Forbidden error with Django and mod_wsgi
提问by g4ur4v
I created Django project in home directory so it is in home directory.
我在主目录中创建了 Django 项目,因此它位于主目录中。
Setup
设置
Django Verison : 1.5.1
Python Version : 2.7.5
mod_wsgi Version: 3.4
Home Directory : /home/aettool
Contents of /home/aettool/aet/apache/django.wsgi
的内容 /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 of httpd.conf
联系我们 httpd.conf
WSGIScriptAlias / /home/aettool/aet/apache/django.wsgi
<Directory /home/aettool/aet/apache>
Order deny,allow
Allow from all
</Directory>
Error in error_log
错误 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
Contents of urls.py
的内容 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
权限 /home/aettool/aet : 775
Permissions of /home/aettool/aet/apache : 755
权限 /home/aettool/aet/apache : 755
Permissions of django.wsgi file : 664
权限 django.wsgi file : 664
I am getting error on browser 403 Forbidden
You don't have permission to access / on this server.
我在浏览器上出错 403 Forbidden
You don't have permission to access / on this server.
Please help me out with the configuration .
请帮我进行配置。
EDIT
编辑
For now I am moving forward by changing
现在我正在通过改变前进
<Directory />
AllowOverride none
Require all denied
</Directory>
to
到
<Directory />
Order deny,allow
Allow from all
</Directory>
So,this has definitely something to do with httpd.conf
file configuration,but my worry is that I only added 5 lines in that file and not able to figure out what's wrong .
所以,这肯定与httpd.conf
文件配置有关,但我担心的是我只在该文件中添加了 5 行,无法弄清楚出了什么问题。
回答by Sdra
Apparently this is an issue that is related to Apache 2.4 and older versions. You need to replace in your apache configuration:
显然,这是一个与 Apache 2.4 及更早版本相关的问题。您需要在 apache 配置中替换:
Allow from all
with
和
Require all granted
in the <Files wsgi.py>
section
在该<Files wsgi.py>
部分
回答by dnozay
You can use the following:
您可以使用以下内容:
<Directory /home/aettool/aet/apache>
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
</Directory>
回答by jk - Reinstate Monica
There is one other gotcha:
还有一个问题:
Check your httpd.conf file for the following configuration:
检查您的 httpd.conf 文件以获取以下配置:
<IfModule mime_module>
AddHandler cgi-script .cgi .pl .py
</IfModule>
This will cause the error.
这将导致错误。
.py MUST NOT be configured as a CGI script
.py 不得配置为 CGI 脚本
回答by erajuan
This has been reported in Django ticket 19319:
这已在 Django 票 19319 中报告:
https://code.djangoproject.com/ticket/19319
https://code.djangoproject.com/ticket/19319
Your Apache config now needs the following for your file wsgi.py
.
您的 Apache 配置现在需要您的文件的以下内容wsgi.py
。
<Directory /path/to/your/wsgi-script>
<Files wsgi.py>
Order deny,allow
Allow from all
Require all granted
</Files>
</Directory>
回答by Abhilash
Linux systems usually don't allow other users to read inside the home directory, and as Apache runs as root, mod_wsgi will not be able to access the inside of the home directory. Try:
Linux 系统通常不允许其他用户读取主目录内部,并且由于 Apache 以 root 身份运行,因此 mod_wsgi 将无法访问主目录内部。尝试:
sudo chmod 755 /home/<username>