apache 使用 mod_wsgi 安装 Django
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1195260/
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
Installing Django with mod_wsgi
提问by marcoslhc
I wrote an application using Django 1.0. It works fine with the django test server. But when I tried to get it into a more likely production enviroment the Apache server fails to run the app. The server I use is WAMP2.0. I've been a PHP programmer for years now and I've been using WAMPServer since long ago. I installed the mod_wsgi.so and seems to work just fine (no services error) but I can't configure the httpd.conf to look at my python scripts located outside the server root.
我使用 Django 1.0 编写了一个应用程序。它适用于 django 测试服务器。但是当我尝试将其放入更有可能的生产环境时,Apache 服务器无法运行该应用程序。我使用的服务器是WAMP2.0。我多年来一直是一名 PHP 程序员,很久以前我就一直在使用 WAMPServer。我安装了 mod_wsgi.so 并且似乎工作得很好(没有服务错误),但我无法配置 httpd.conf 来查看位于服务器根目录之外的 python 脚本。
For now, I'm cool with overriding the document root and serve the django app from the document root instead so the httpd.conf line should look like this:
现在,我很乐意覆盖文档根目录并从文档根目录提供 django 应用程序,因此 httpd.conf 行应如下所示:
WSGIScriptAlias / C:/Users/Marcos/Documents/mysite/apache/django.wsgi
but the server's response is a 403 Forbidden
但服务器的响应是 403 Forbidden
回答by Graham Dumpleton
You have:
你有:
WSGIScriptAlias / /C:/Users/Marcos/Documents/mysite/apache/django.wsgi
That is wrong as RHS is not a valid Windows pathname. Use:
这是错误的,因为 RHS 不是有效的 Windows 路径名。用:
WSGIScriptAlias / C:/Users/Marcos/Documents/mysite/apache/django.wsgi
That is, no leading slash before the Windows drive specifier.
也就是说,在 Windows 驱动器说明符之前没有前导斜线。
Other than that, follow the mod_wsgi documentation others have pointed out.
除此之外,请遵循其他人指出的 mod_wsgi 文档。
Poster edited question to change what now would appear to be a typo in the post and not a problem with his configuration.
海报编辑了问题以更改现在看起来是帖子中的错字而不是他的配置问题。
If that is the case, next causes for a 403 are as follows.
如果是这种情况,403 的下一个原因如下。
First is that you need to also have:
首先,您还需要具备:
<Directory C:/Users/Marcos/Documents/mysite/apache>
Order deny,allow
Allow from all
</Directory>
If you don't have that then Apache isn't being granted rights to serve a script from that directory and so will return FORBIDDEN (403).
如果您没有,那么 Apache 就没有被授予从该目录提供脚本的权限,因此将返回 FORBIDDEN (403)。
Second is that you do have that, but don't acknowledge that you do, and that that directory or the WSGI script file is not readable by the user that the Apache service runs as under Windows.
其次是您确实拥有它,但不承认您拥有该目录或 WSGI 脚本文件,并且 Apache 服务在 Windows 下运行的用户无法读取该目录或 WSGI 脚本文件。
回答by S.Lott
Have you seen http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango?
你见过http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango吗?
You need more than one line to assure that Apache will play nicely.
您需要不止一行来确保 Apache 运行良好。
Alias /media/ /usr/local/django/mysite/media/
<Directory /usr/local/django/mysite/media>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias / /usr/local/django/mysite/apache/django.wsgi
<Directory /usr/local/django/mysite/apache>
Order deny,allow
Allow from all
</Directory>
The <Directory>, as well as appropriate file system ownership and permissions are essential.
的<Directory>,以及适当的文件系统的所有权和权限是必不可少的。
The usr/local/django/mysite/apachedirectory has your Python/Django app and the all-important django.wsgifile. You must provide permissions on this directory.
该usr/local/django/mysite/apache目录包含您的 Python/Django 应用程序和最重要的django.wsgi文件。您必须提供对此目录的权限。
回答by Sergey Konozenko
mod_wsgi's documentation is very good. Try using their quick configuration guide and go from there: http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide
mod_wsgi 的文档非常好。尝试使用他们的快速配置指南并从那里开始:http: //code.google.com/p/modwsgi/wiki/QuickConfigurationGuide

