0

This is my first time trying to setup a webserver with Django. I've been banging my head against the wall in trying to set this up for a while now and I can't seem to find any resources that explains this in a newbie formatted step by step manner.

I've installed and setup apache and mod_wsgi on my EC2 instance. How do I map the URLs of my app set in my urls.py file to apache? Locally, I can get my app to work my entering 127.0.0.1:8000/flickr/photousers by running it on the Django development server. I'm trying to be able to get this to work on my public dns as http://ec2-122-248-194-176.ap-southeast-1.compute.amazonaws.com/flickr/photouser with apache and mod_wsgi.

When I restart my Apache server, I also get this error but with OK status [error] (EAI 2)Name or service not known: Could not resolve host name *.80 -- ignoring

Below lists the relevant snippets

django.wsgi file

import os,sys

apache_configuration = os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append(/home/djangotest/flickr)
#sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'flickr.settings'

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

httpd.conf file

<VirtualHost *.80>
    DocumentRoot /home/djangotest/flickr
    ServerName ec2-122-248-194-176.ap-southeast-1.compute.amazonaws.com
    ErrorLog /home/djangotest/flickr/logs/apache_error.log
    CustomLog /home/djangotest/flickr/logs/apache_access.log combined
    WSGIScriptAlias / /home/djangotest/flickr/apache/django.wsgi

    <Directory /home/djangotest/flickr/media>
        Order deny,allow
        Allow from all
    </Directory>

    <Directory /home/djangotest/flickr/apache>
        Order deny,allow
        Allow from all
    </Directory>

    LogLevel warn

    WSGIDaemonProcess ec2-122-248-194-176.ap-southeast-1.compute.amazonaws.com user=djangotest processes=2 threads=25
    WSGIProcessGroup ec2-122-248-194-176.ap-southeast-1.compute.amazonaws.com

    Alias /media/ /home/djangotest/flickr/media/
</VirtualHost>

urls.py

from django.conf.urls.defaults import *

urlpatterns = patterns('',
    # Example:
    (r'flickr/', include('flickrphotobrowser.urls')),
)

urls.py (located in my app)

from django.conf.urls.defaults import *

from flickrphotobrowser.views import *

urlpatterns = patterns('flickrphotobrowser.views',
        (r'^phototags/$', contenttags),
        (r'^photouser/$', contentuser),
)

settings.py

ROOT_URLCONF = 'flickr.urls'

TEMPLATE_DIRS = (
        os.path.join(os.path.basename(__file__), 'templates'),
    #'home/nai/Projects/flickr/flickrphotobrowser/templates', # THIS IS FOR LOCAL ONLY
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'flickr.flickrphotobrowser',
)

Should I include any other snippets to help troubleshoot the problem? Thanks.

1
  • Couple of typos: the method names in the urls should be enclosed in quotations as well. So it should be 'contenttags' and 'contentuser'
    – Nai
    Mar 23, 2011 at 9:12

1 Answer 1

1

In your httpd conf, change:

<VirtualHost *.80>

to

<VirtualHost *:80>

and restart Apache.

If that doesn't fix it, you could also try adding:

sys.path.append('/home/djangotest')

to your django.wsgi file.

4
  • Ok changing to <VirtualHost *:80> worked but now I'm getting an error You don't have permission to access /flickr/photouser on this server.(OMG A TYPO URGHHHHHHHHHH)
    – Nai
    Mar 23, 2011 at 8:25
  • Don't worry, Steve has a mistake in his answer as well. The path supplied to sys.path.append should be quoted but ServerFault doesn't allow trivial edits for me. BTW, also make sure you have 'NameVirtualHost *:80' directive as well else name virtual hosts will not resolve properly. Mar 23, 2011 at 10:33
  • @Graham Yes I saw that in the apache error logs! I also had a couple of permission issues which I fixed by changing the User and Group values. I was able to debug the rest of my problems after making the change he spotted.
    – Nai
    Mar 23, 2011 at 10:46
  • 1
    You shouldn't normally be changing the User/Group of Apache itself. If using mod_wsgi you would be better off using daemon mode and have just the Python web application process run as different user/group y setting the user/group options to WSGIDaemonProcess. Only the WSGI script file then has to be readable/accessible to Apache user. Watch 'code.google.com/p/modwsgi/wiki/…'. Mar 23, 2011 at 20:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .