nlr25
nlr25

Reputation: 1635

Django deployment with Apache on AWS -- Directory Structure

I have a django app with the following structure

web/
   manage.py
   settings.py
   wsgi.py
   urls.py
   /subapp1/
   /subapp2/

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

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

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

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>

I did a sudo a2ensite ec2-XXX.us-west-1.compute.amazonaws.com to have the site-enabled.

How do I get my webpages served by Apache? I realize this may be a weird file structure.

Upvotes: 0

Views: 493

Answers (1)

Graham Dumpleton
Graham Dumpleton

Reputation: 58563

Replace your wsgi.py with a WSGI hello world and take Django out of the picture.

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:

Make sure you try that hello world WSGI application first though rather than just jump to trying the solution described in that documentation.

Upvotes: 1

Related Questions