1

I am having a lot of trouble figuring out what is wrong with my installation. This is my first time setting up a django app on a production server so I think I just need a little bit of help figuring out how to configure the path to the settings module. This is what I have in my httpd.conf file.

<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName  nodeline.com
WSGIScriptAlias / /home/mysite/mysite/wsgi.py

</VirtualHost>

I started a basic project in the /home directory called mysite using this command.

django-admin.py startproject mysite

This is what is coming out in the apache erro logs:

[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132] mod_wsgi (pid=26120): Exception occurred processing WSGI script '/home/mysite/mysite/wsgi.py'.
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132] Traceback (most recent call last):
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132]   File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 236, in __call__
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132]     self.load_middleware()
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132]   File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 45, in load_middleware
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132]     for middleware_path in settings.MIDDLEWARE_CLASSES:
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132]   File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 53, in __getattr__
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132]     self._setup(name)
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132]   File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 48, in _setup
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132]     self._wrapped = Settings(settings_module)
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132]   File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 134, in __init__
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132]     raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
[Sat Jul 06 02:49:42 2013] [error] [client 119.63.193.132] ImportError: Could not import settings 'mysite.settings' (Is it on sys.path?): No module named mysite.settings

This is what is inside the /home/mysite/mysite/wsgi.py file (it is the default configuration that comes with the file when starting a project.):

"""
WSGI config for mysite project.

This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.

Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.

"""
import os

# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "mysite.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)

I really just need to get the standard screen to show up and I know I can move forward from there. I should also note that when I start up the app just using the django built in development server it works. I started it up on port 8000 using this command:

python manage.py runserver 0:8000

When visiting nodeline.com:8000 it works.

enter image description here

Spencer Cooley
  • 8,471
  • 16
  • 48
  • 63

3 Answers3

0

Make sure you add the path of your settings to settings.py into your wsgi.py:

import sys, os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
AMADANON Inc.
  • 5,753
  • 21
  • 31
0
Let me try to help you.
i hope you are using ubuntu like OS.
first after installed apache and get it works.
install mod-wsgi which integrate mod-python by:
sudo apt-get install libpache2-mod-wsgi
and create a directory named apache in your Project directory
open that directory [project]/apache and create a file django.wsgi.py
and write this code inside
wsgi_dir =os.path.abspath(os.path.dirname(__file__))
project_dir = os.path.dirname(wsgi_dir)
sys.path.append(project_dir)
project_settings =os.join(project_dir,'settings')
os.environ['DJANGO_SETTINGS_MODULE'] ='[project-name].settings'
import django.core.handlers.wsgi
application =django.core.handlers.wsgi.WSGIHandler()

In your apache server directory and in the sites-available create a file which going
to reflect your project name and inside that file write your code like this:
NameVirtualHost 127.0.0.1:8080
<VirtualHost 127.0.0.1:8080>
ServerAdmin webmaster@you-domain.com
    ServerName your-domain.com
ServerAlias  your-domain.com

Alias /static /path/to/your/project/static

DocumentRoot /path/to/your/project
WSGIScriptAlias / /path/to/your/project/apache/django.wsgi

Errorlog /var/log/apache2/error.log
#ErrorLog ${APACHE_LOG_DIR}/error.log
#ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

# CustomLog /home/user/Customerlog/
#CustomLog ${APACHE_LOG_DIR}/access.log combined
CustomLog /var/log/apache2/access.log combined

RPAFenable On
RPAFsethostname On
RPAFproxy_ips 127.0.0.1
</VirtualHost>

under your terminal type:
sudo a2ensite [name-of-file create under site-available]

open ports.conf and type listen:80
and in the urls.py remove the DEBUG_MODE and restart apache
sudo service apache2 restart
IF YOU ARE USING STATIC FILES too :
you have to install nginx (engine X) and configured it before got the statics files work
with apache.
drabo2005
  • 1,076
  • 1
  • 10
  • 16
0

Have you read the Django documentation on mod_wsgi deployment? In:

it talks about the need to set the Python module search path.

I would suggest you go read the documentation.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134