Apache mod_wsgi 错误:禁止您无权访问此服务器上的 /
我使用的是 Ubuntu 10.04。
我在 /home/wong2/Code/python/django2/
下创建一个名为 atest
的 django 项目 并在同一目录中创建一个 wsgi 文件 setting.wsgi
这是 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 中的内容:
<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,它说
禁止
您无权访问/ 在此服务器上。
多谢。
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()
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>
The problem is, when I visit http://localhost, it says
Forbidden
You don't have permission to access /
on this server.
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
第二个目录块与您安装 WSGI 脚本文件的位置不匹配。虽然将 WSGI 脚本文件粘贴在源代码或其他敏感文件所在的位置(即同一目录或子目录)是非常糟糕的做法。相反,您应该将其放在自己的子目录中。因此:
因此,在“atest”下创建“apache”子目录。将“setting.wsgi”移动到“apache”子目录并将配置更改为上面的内容。
您的问题也可能是由于您的主目录的权限限制造成的,因为 Apache 无法看到内部。
请观看:
http://code.google.com/p/ modwsgi/wiki/WhereToGetHelp?tm=6#Conference_Presentations,
因为它解释了这些权限问题以及代码和 WSGI 脚本文件的粘贴位置等问题。
另请阅读:
http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango< /a>
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:
So, create 'apache' subdirectory under 'atest'. Move 'setting.wsgi' into that 'apache' subdirectory and change config to above.
Your problem also may be caused by restrictive permisions on your home directory as Apache cannot see inside.
Go watch:
http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6#Conference_Presentations
as it explains these permissions problems as well as issues like where to stick your code and the WSGI script file.
Also read:
http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
对于 Django 1.5+,您应该使用文档中描述的建议方式:
https://docs。 djangoproject.com/en/1.7/howto/deployment/wsgi/modwsgi/
With Django 1.5+ you should use the suggested way described in the documentation:
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/modwsgi/
由于文件权限受限,我也遇到了同样的问题。
默认情况下,您的主文件夹用户具有以下设置:
意思是除了你自己之外没有其他人能够浏览该文件夹。
将执行选项添加到文件夹解决了我的问题
I had the same problem due to restricted file permissions.
By default your home folder user has the settings:
meaning that no one else but yourself is able to even browse that folder.
Adding execute option to the folder fixed my problem
尝试 http://localhost/index.html 是否显示 apache 页面?
如果你的 wsgi 在 root 上配置正确,它就不会。
您收到该错误消息是因为您可能会向网络服务器询问 www 文件夹的目录列表
edit:
我的项目始终位于
/var/pyproj//pysrc/
和我放入的服务器文件
/var/py_proj//server/
这是我的 wsgi 脚本
,我使用 vhost.conf
,我将其包含在文件中的站点可用文件夹中,该文件看起来像
httpd.conf 是空的。 Apache 在发送静态文件方面也很糟糕,所以我在端口 8080 上设置了 apache,在端口 80 上设置了 nginx,转发到 apache。你应该能够只更改我的站点可用文件上的端口以在没有 nginx 的情况下运行它,但我不会那样运行
try http://localhost/index.html does that show the apache page?
If you wsgi is configured on root correctly it wont.
You get that error message because you might be asking the webserver for the directory listing of www folder
edit:
My projects are always in
/var/pyproj//pysrc/
and server files i put in
/var/py_proj//server/
Here is my go to wsgi script
and i use a vhost.conf
which i include in the sites-available folder in a file that looks like this
httpd.conf is empty. Apache is also terrible at sending static files so i have my apache setup on port 8080 and nginx setup on port 80 which forwards to apache. You should be able to just change the port on my sites-avaiable file to run it without nginx but i would not go live that way
您可能会惊讶地发现您的 WSGI 有它的主目录!在我诚然天真的 wsgi_mod 安装中,它是 / - 我非常惊讶,我必须编写此脚本来确保:
这意味着导入的应用程序将需要找到完整路径,例如:
这是(Google)推荐的方法这:
You may get a surprise where your WSGI has its home directory! On my admittedly naive wsgi_mod installation, it is / - I was so surprised I had to write this script to make sure:
That means imported applications will need a full path to be found, e.g.:
This is the recommended (by Google) approach to this: