使用WSGI和apach设置Django

2024-05-12 22:51:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我被卖的是mod_wsgi和apache,而不是mod_python。 我已经安装了所有部件(django、apache、mod_wsgi),但是在部署时遇到了问题。

我在OSX10.5上使用Apache2.2和Django1.0b2,mod_wsgi-2.3

我的申请叫做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时,我得到的是目录列表,而不是呈现的网站。我认为我已经正确地遵循了教程,但显然是不对的。我能做些什么让它工作?


Tags: djangofrommodwsgiosorderaliasall
3条回答

It works. I have no idea why, but it does.

供将来参考:

它之所以工作是因为Apache按顺序处理alias指令,并使用第一个匹配项。它总是在WSGIScriptAlias之前点击Alias /,这将匹配任何内容。

^{} documentation

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之后,它就不重要了,它仍然具有优先权。

如果删除Alias /指令会发生什么情况?

相关问题 更多 >