2

在过去的几天里,我一直在努力使用Bitnami Djangostack在 Amazon EC2 上部署 Django 应用程序。当我去我的主页(比如http://example.com)时,我看到默认的 bitnami 页面(/opt/bitnami/apache2/htdocs/index.html),但是,当我打开http://example.com/ portnoy,我得到“内部服务器错误”。但众所周知,如果 mod_wsgi 设置正确,来自 httpd.conf 的 DocumentRoot 值将被忽略,因此,我应该在访问http://example.com时看到我的 Django 应用程序。本质上,主要错误是 - '目标 WSGI 脚本不能作为 Python 模块加载'。两个问题:1) 任何想法如何修复这些 mod_wsgi 错误(Apache 日志如下)?2)如何禁用默认/opt/bitnami/apache2/htdocs/index.html页面并在访问http://example.com时从 django 应用程序显示我的主页?先感谢您!

细节

在我的 EC2 实例上,我正在运行带有 DjangoStack 1.4-1 的 64 位 Ubuntu 12.04。我的 Django 项目位于此处 - /opt/bitnami/apps/django/django_projects/portnoy

root@example:/opt/bitnami/apps/django/django_projects/portnoy# ls
manage.py README.md settings.py site_media users Procfile sandbox static test.py topics urls.py views.py __init__.pyc templates testviews.py

Apache 错误日志 ( /opt/bitnami/apache2/logs/error_log ):

[Wed Jul 04 02:29:00 2012] [error] [client 140.180.6.212] File does not exist: /opt/bitnami/apache2/htdocs/favicon.ico
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] mod_wsgi (pid=3990): Target WSGI script '/opt/bitnami/apps/django/scripts/django.wsgi' cannot be loaded as Python module.
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] mod_wsgi (pid=3990): Exception occurred processing WSGI script '/opt/bitnami/apps/django/scripts/django.wsgi'.
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] Traceback (most recent call last):
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212]   File "/opt/bitnami/apps/django/scripts/django.wsgi", line 8, in <module>
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212]     import django.core.handlers.wsgi
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212]   File "/opt/bitnami/apps/django/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 8, in <module>
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212]     from django import http
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212]   File "/opt/bitnami/apps/django/lib/python2.7/site-packages/django/http/__init__.py", line 119, in <module>
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212]     from django.http.multipartparser import MultiPartParser
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212]   File "/opt/bitnami/apps/django/lib/python2.7/site-packages/django/http/multipartparser.py", line 13, in <module>
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212]     from django.utils.text import unescape_entities
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212]   File "/opt/bitnami/apps/django/lib/python2.7/site-packages/django/utils/text.py", line 4, in <module>
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212]     from gzip import GzipFile
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212]   File "/opt/bitnami/python/lib/python2.7/gzip.py", line 10, in <module>
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212]     import io
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212]   File "/opt/bitnami/python/lib/python2.7/io.py", line 60, in <module>
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212]     import _io
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] ImportError: /opt/bitnami/python/lib/python2.7/lib-dynload/_io.so: undefined symbol: PyUnicodeUCS2_AsEncodedString
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] File does not exist: /opt/bitnami/apache2/htdocs/favicon.ico
[Wed Jul 04 02:44:00 2012] [error] [client 140.180.6.212] File does not exist: /opt/bitnami/apache2/htdocs/favicon.ico

让我快速介绍一下文件的内容,以使案例更加具体。

这是我的/etc/apache2/sites-available/default文件

<VirtualHost *:80>
ServerAdmin root@example.com
ServerName example.com

Alias /site_media/ /opt/bitnami/apps/django/django_projects/portnoy/site_media/
Alias /static/ /opt/bitnami/apps/django/lib/python2.7/site-packages/django/contrib/admin/static/
Alias /robots.txt /opt/bitnami/apps/django/django_projects/portnoy/site_media/robots.txt
Alias /favicon.ico /opt/bitnami/apps/django/django_projects/portnoy/site_media/favicon.ico

CustomLog "|/usr/sbin/rotatelogs /opt/bitnami/apps/django/django_projects/logs/access.log.%Y%m%d-%H%M%S 5M" combined
ErrorLog "|/usr/sbin/rotatelogs /opt/bitnami/apps/django/django_projects/logs/error.log.%Y%m%d-%H%M%S 5M"
LogLevel warn

WSGIProcessGroup example.com
WSGIScriptAlias / /opt/bitnami/apps/django/scripts/django.wsgi

<Directory /opt/bitnami/apps/django/django_projects/portnoy/site_media>
Order deny,allow
Allow from all
Options -Indexes FollowSymLinks
</Directory>

<Directory /opt/bitnami/apps/django/django_projects/portnoy/conf/apache>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>

这是我的/opt/bitnami/apps/django/scripts/django.wsgi文件

import os, sys

sys.path.append('/opt/bitnami/apps/django/lib/python2.7/site-packages/')
sys.path.append('/opt/bitnami/apps/django/django_projects')
sys.path.append('/opt/bitnami/apps/django/django_projects/portnoy')
os.environ['DJANGO_SETTINGS_MODULE'] = 'portnoy.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

这是/opt/bitnami/apache2/conf/httpd.conf文件的相关部分:

ServerRoot "/opt/bitnami/apache2"
Listen 80
ServerName example.com
DocumentRoot "/opt/bitnami/apache2/htdocs"
LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonHome /opt/bitnami/python
Include "/opt/bitnami/apache2/conf/ssi.conf"
Include "/opt/bitnami/apps/django/conf/django.conf"
Include "/opt/bitnami/apache2/conf/bitnami/httpd.conf"

注意:我在这篇文章中使用 example.com 来指代我实际拥有的域。

4

1 回答 1

2

这已在以下位置得到回答:

https://groups.google.com/forum/?fromgroups#!topic/modwsgi/YLDd6ojQrzo

于 2012-07-04T23:45:06.290 回答