Apache mod_wsgi 错误:禁止您无权访问/在此服务器上
我使用的是 Ubuntu 10.04.
我在 /home/wong2/Code/python/django2/
下创建了一个名为 atest
的 django 项目并在同一目录下创建一个wsgi文件setting.wsgi
下面是setting.wsgi
的内容:
I'm using Ubuntu 10.04.
I create a django project under /home/wong2/Code/python/django2/
named atest
and create a wsgi file setting.wsgi
in the same directory
Here is the content of setting.wsgi
:
import os
import sys
path = '/home/wong2/Code/python/django2'
if path not in sys.path:
sys.path.append(path)
os.environ["DJANGO_SETTINGS_MODULE"] = "atest.settings"
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
这是我添加到我的 httpd.conf 中的内容:
and here is what I add to my my httpd.conf:
<VirtualHost *:80>
ServerName localhost
WSGIScriptAlias / /home/wong2/Code/python/django2/setting.wsgi
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
<Directory "/home/wong2/Code/python/django2/atest">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
问题是,当我访问 http://localhost 时,它说
The problem is, when I visit http://localhost, it says
禁止
您无权访问/在这台服务器上.
You don't have permission to access / on this server.
非常感谢.
第二个目录块与您安装 WSGI 脚本文件的位置不匹配.尽管将 WSGI 脚本文件粘贴在存在源代码或其他敏感文件的位置,即相同的目录或子目录中,这是非常糟糕的做法.相反,你应该把它放在它自己的子目录中.因此:
The second directory block doesn't match where you have your WSGI script file installed. It is very bad practice though to stick the WSGI script file in a location where source code or other sensitive files exist, ie., same directory or sub directory. Instead you should stick it in a sub directory of its own. Thus:
WSGIScriptAlias / /home/wong2/Code/python/django2/atest/apache/setting.wsgi
<Directory "/home/wong2/Code/python/django2/atest/apache">
Order allow,deny
Allow from all
</Directory>
因此,在test"下创建apache"子目录.将 'setting.wsgi' 移动到那个 'apache' 子目录并将配置更改为上面的内容.
So, create 'apache' subdirectory under 'atest'. Move 'setting.wsgi' into that 'apache' subdirectory and change config to above.
您的问题也可能是由于 Apache 无法看到您的主目录中的限制性权限造成的.
Your problem also may be caused by restrictive permisions on your home directory as Apache cannot see inside.
去观看:
http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6#Conference_Presentations
因为它解释了这些权限问题以及诸如将代码和 WSGI 脚本文件粘贴在哪里等问题.
as it explains these permissions problems as well as issues like where to stick your code and the WSGI script file.
另请阅读: