[英]403 Forbidden error with Django and mod_wsgi
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
权限/home/aettool/aet : 775
Permissions of /home/aettool/aet/apache : 755
/home/aettool/aet/apache : 755
权限/home/aettool/aet/apache : 755
Permissions of django.wsgi file : 664
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 行并且无法弄清楚出了什么问题。
Apparently this is an issue that is related to Apache 2.4 and older versions.显然,这是一个与 Apache 2.4 及更早版本相关的问题。 You need to replace in your apache configuration:
您需要在 apache 配置中替换:
Allow from all
with和
Require all granted
in the <Files wsgi.py>
section在
<Files wsgi.py>
部分
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>
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
的以下wsgi.py
。
<Directory /path/to/your/wsgi-script>
<Files wsgi.py>
Order deny,allow
Allow from all
Require all granted
</Files>
</Directory>
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 脚本
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. Linux 系统通常不允许其他用户读取主目录内部,并且由于 Apache 以 root 身份运行,因此 mod_wsgi 将无法访问主目录内部。 Try:
尝试:
sudo chmod 755 /home/<username>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.