在 AWS 上使用 Apache 部署 Django -- 目录结构 [英] Django deployment with Apache on AWS -- Directory Structure
问题描述
我有一个具有以下结构的 django 应用
I have a django app with the following structure
web/
manage.py
settings.py
wsgi.py
urls.py
/subapp1/
/subapp2/
当部署在开发服务器 runserver
上时,一切都可以正常连接并正常工作.当我部署整个 web
应用程序时,我的网页都没有提供.没有 500
或 404
错误.并且错误日志只显示:
When deployed on the development server runserver
, everything links and works correctly. When I deploy the entire web
app, none of my webpages are served. There is no 500
or 404
error. And the error logs only show:
[notice] caught SIGTERM, shutting down
[notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
我的 Apache2.2.2 设置如下:
I have the following set up for my Apache2.2.2:
wsgi.py:
import os
import sys
import site
site.addsitedir('/home/ubuntu/.virtualenvs/venv/local/lib/python2.7/site-packages')
sys.path.append('/var/www/ec2-XXX.us-west-1.compute.amazonaws.com/')
sys.path.append('/var/www/ec2-XXX.us-west-1.compute.amazonaws.com/web')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "web.settings")
activate_env=os.path.expanduser("/home/ubuntu/.virtualenvs/venv/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
/etc/apache2/httpd.conf
/etc/apache2/httpd.conf
WSGIScriptAlias / /var/www/ec2-XXX.us-west-1.compute.amazonaws.com/web/wsgi.py
WSGIPythonPath /var/www/ec2-XXX.us-west-1.compute.amazonaws.com/web:/home/ubuntu/.virtualenvs/venv/local/lib/python2.7/site-packages
alias /static /var/www/ec2-XXX.us-west-1.compute.amazonaws.com/web/static
<Directory /var/www/ec2-XXX.us-west-1.compute.amazonaws.com/web>
<Files wsgi.py>
Order allow, deny
Allow from all
</Files>
</Directory>
/etc/apache2/sites-available/ec2-XXX.us-west-1.compute.amazonaws.com
/etc/apache2/sites-available/ec2-XXX.us-west-1.compute.amazonaws.com
WSGIPythonPath /var/www/ec2-XXX.us-west-1.compute.amazonaws.com/web:/home/ubuntu/.virtualenvs/venv/local/lib/python2.7/site-packages
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName ec2-XXX.us-west-1.compute.amazonaws.com
DocumentRoot /var/www/ec2-XXX.us-west-1.compute.amazonaws.com/web
WSGIScriptAlias / /var/www/ec2-XXX.us-west-1.compute.amazonaws.com/web/wsgi.py
<Directory /var/www/ec2-XXX.us-west-1.compute.amazonaws.com/web>
<Files wsgi.py>
Order allow,deny
Allow from all
</Files>
</Directory>
我做了一个 sudo a2ensite ec2-XXX.us-west-1.compute.amazonaws.com
来启用站点.
I did a sudo a2ensite ec2-XXX.us-west-1.compute.amazonaws.com
to have the site-enabled.
如何让我的网页由 Apache 提供服务?我意识到这可能是一个奇怪的文件结构.
How do I get my webpages served by Apache? I realize this may be a weird file structure.
推荐答案
用一个 WSGI hello world 替换你的 wsgi.py,并把 Django 排除在外.
Replace your wsgi.py with a WSGI hello world and take Django out of the picture.
如果可行,那么一种可能性是您使用的第三方扩展模块与 Python 子解释器不兼容并且处于死锁状态,导致服务器挂起请求而不返回任何内容.更多详情请见:
If that works then one possibility is the third party extension modules you are using are not compatible with Python sub interpreters and are dead locking, causing the server to hang on the request and not return anything. For more details see:
请务必先尝试 hello world WSGI 应用程序,而不是直接尝试该文档中描述的解决方案.
Make sure you try that hello world WSGI application first though rather than just jump to trying the solution described in that documentation.
这篇关于在 AWS 上使用 Apache 部署 Django -- 目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!