linux - 谁能告诉我为什么 Apache 对我的 Django 不起作用?

标签 linux django apache permissions

我在访问我的 domain.com 时遇到了这个问题。我已将此网站与我的其他网站进行了比较,该网站具有相同的设置(只是用户名不同!!!)出于某种原因,该网站可以正常工作而这个网站不能。

Forbidden
You don't have permission to access / on this server.
Apache/2.2.3 (Red Hat) Server at www.mydomain.com Port 80

就权限问题而言,我已将用户“apache”添加到拥有所有内容所在文件夹的组“dver”和“svn”。

$ ls -l
total 4
drwxr-xr-x 4 dver svn 4096 Oct 13 19:49 tv

这是我的django.wsgi:

import os
import sys
sys.path.append('/home/dver/tv')
os.environ['PYTHON_EGG_CACHE'] = '/home/dver'
os.environ['DJANGO_SETTINGS_MODULE'] = 'mtv.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

这是在我的 httpd.conf 中:

WSGIScriptAlias / /home/dver/tv/mtv/wsgi/django.wsgi
DocumentRoot "/home/dver/tv/mtv/"
Alias /media/ /home/dver/tv/mtv/media/
<Directory /home/dver/tv/mtv/media>
Order deny,allow
Allow from all
</Directory>

<Directory /home/dver/tv/mtv>
Order deny,allow
Allow from all
</Directory>

如果有人能帮助我,我将不胜感激。

谢谢!

最佳答案

由于代码将作为 Apache 用户运行,因此从文件系统根目录到“/home/dver/tv/mtv/wsgi”的所有目录必须对其他人可读/可执行,或者至少以某种方式 Apache用户,而不仅仅是您的 Django 站点目录。

因此,如果'/home/dver' 有权限'rwxr-x---' 那么它就不会工作。这是人们将 WSGI 脚本文件粘贴到自己的家庭帐户下的最常见问题。操纵组可能有效,但您没有指明该组所有权是否也适用于“/home/dver”。

虽然引用父目录并不重要,但更安全的是:

<Directory /home/dver/tv/mtv/wsgi>
Order deny,allow
Allow from all
</Directory>

也就是说,使用“/home/dver/tv/mtv/wsgi”而不是“/home/dver/tv/mtv”。

另一种可能性是您为操作系统启用了 SELinux 扩展。如果是,您应该正确配置 SELinux,或者可能禁用它以查看它是否可以正常工作。

关于linux - 谁能告诉我为什么 Apache 对我的 Django 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1666125/

相关文章:

Linux/X11下的Java keyPress/keyRelease问题

django - 通过Django create方法传递save参数

php - UTF-8贯穿始终

python - 导入错误: oracle client library with python wsgi

java - Apache POI : Getting wrong number/string values reading from xlsx while xls is workfing fine

linux - 如何将列数据传输到行(使用awk)?

linux - 来自 root 帐户的 Bash 脚本和用户主页 (Linux)

linux - 如何指定在 CentOS 上使用哪个版本的 perl

python - 以 10 为基数的 int() 的文字 : 'testuser' even tho the argument passed is a string

python - 为什么 __dict__ 不是可调用的