在过去的几天里,我一直在努力使用Bitnami Djangostack在Amazon EC2上部署Django应用程序。当我转到我的主页(说http://example.com)时,我会看到默认的bitnami页面( /opt/bitnami/apache2/htdocs/index.html ),但是,当我打开{{3}我得到'内部服务器错误'。但是众所周知,如果mod_wsgi设置正确,httpd.conf中的DocumentRoot值将被忽略,因此,我应该在访问http://example.com/portnoy时看到我的Django应用程序。本质上,主要的错误是 - '目标WSGI脚本无法作为Python模块加载'。两个问题:1)任何想法如何解决这些mod_wsgi错误(Apache日志如下)? 2)如何在访问http://example.com时禁用默认 /opt/bitnami/apache2/htdocs/index.html 页面并从django应用程序显示我的主页?提前谢谢!
在我的EC2实例上,我正在使用DjangoStack 1.4-1运行64位Ubuntu 12.04。我的Django项目位于此处 - / opt / bitnami / apps / django / django_projects / portnoy 。< / p>
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来引用我实际拥有的域名。
答案 0 :(得分:2)