使用WSGI和Apache设置django
时间:2020-03-05 18:45:38 来源:igfitidea点击:
我已经通过mod_wsgi和apache而不是mod_python出售了。
我已经安装了所有部件(django,apache,mod_wsgi),但是部署时遇到了问题。
我在使用Apache 2.2和Django 1.0b2,mod_wsgi-2.3的osx 10.5上
我的应用程序称为tred。
以下是相关文件:
httpd-vhosts(包含在httpd-conf中)
NameVirtualHost tred:80 ServerName tred Alias /admin_media /usr/lib/python2.5/site-packages/django/contrib/admin/media Order allow,deny Allow from all Alias /media /Users/dmg/Sites/tred/media Order allow,deny Allow from all Alias / /Users/dmg/Sites/tred/ Order allow,deny Allow from all WSGIScriptAlias / /Users/dmg/Sites/tred/mod_wsgi-handler.wsgi WSGIDaemonProcess tred user=dmg group=staff processes=1 threads=10 WSGIProcessGroup tred
mod_wsgi-handle.wsgi
import sys import os sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..') os.environ['DJANGO_SETTINGS_MODULE'] = 'tred.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
当我转到http:// tred时,我得到的是目录列表,而不是呈现的网站。我认为我正确地遵循了这些教程,但这显然是不对的。我该怎么做才能使这项工作?
解决方案
回答
如果删除Alias /
指令,会发生什么?
回答
It works. I have no idea why, but it does.
备查:
之所以有效,是因为Apache按顺序处理别名指令,并使用第一个匹配项。它总是在WSGIScriptAlias
之前命中Alias /
,它将匹配任何东西。
从mod_alias
文档中:
First, all Redirects are processed before Aliases are processed, and therefore a request that matches a Redirect or RedirectMatch will never have Aliases applied. Second, the Aliases and Redirects are processed in the order they appear in the configuration files, with the first match taking precedence.
回答
请注意,Alias和WSGIScriptAlias指令的优先级不同。因此,它们将不会按照写入的文件顺序进行处理。相反,所有Alias指令都优先于WSGIScriptAlias指令。因此,如果'/'的别名出现在WSGIScriptAlias之后并没有关系,它将仍然具有优先权。