Things went much better fixing the name of the wsgi file, but I've struggling with the static files. I don't have a lot of users and I'm not that worried about performance, but I'm interested in having the static content password projected. Therefore I'd like password protected under the django views rather than server the static content through apache.
Here's the httpd.conf:
<Directory /var/www/django/static>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias / /var/www/django/mysite/apache/django.wsgi
<Directory /var/www/django/mysite/apache/mysite>
Order allow,deny
Allow from all
</Directory>
#Alias /static/ /var/www/django/static/
If I remove the comment # from the Alias command, everything works, but my static content is exposed on the public web, too. With the Alias command commented out, I don't see the static content anymore, although the template appears correctly.
I used the collectstatic command, (although it' not really relevant as I don't have lots of apps), so the static content is in /var/www/django/static.
Here is the settings.py pertaining to STATIC:
STATIC_ROOT = '/var/www/django/static/'
# URL prefix for static files.
# Example: "
http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
I added the instrumentation to the settings.py recommended in
http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.htmlI see verbose output in the error log, so I'll try to abstract what might be useful. /var/forecast_charts is the URL
[Thu Aug 30 15:22:12 2012] [notice] Apache/2.2.22 (Unix) DAV/2 mod_python/3.3.1 Python/2.7.1 mod_wsgi/3.4 PHP/5.3.13 mod_ssl/2.2.22 OpenSSL/1.0.0j-fips mod_perl/2.0.4 Perl/v5.12.4 configured -- resuming normal operations
[Thu Aug 30 15:22:12 2012] [info] Server built: Feb 13 2012 14:50:23
[Thu Aug 30 15:22:12 2012] [info] mod_wsgi (pid=14827): Attach interpreter ''.
[Thu Aug 30 15:22:12 2012] [info] mod_wsgi (pid=14829): Attach interpreter ''.
[Thu Aug 30 15:22:12 2012] [info] mod_wsgi (pid=14828): Attach interpreter ''.
[Thu Aug 30 15:22:16 2012] [info] mod_wsgi (pid=14822): Create interpreter '127.0.0.1|'.
[Thu Aug 30 15:22:16 2012] [info] [client 127.0.0.1] mod_wsgi (pid=14822, process='', application='127.0.0.1|'): Loading WSGI script '/var/www/django/mysite/apache/django.wsgi'., referer:
http://127.0.0.1/var/forecast_charts[Thu Aug 30 15:22:17 2012] [error] __name__ = mysite.settings
[Thu Aug 30 15:22:17 2012] [error] __file__ = /var/www/django/mysite/apache/../mysite/settings.pyc
[Thu Aug 30 15:22:17 2012] [error] os.getpid() = 14822
[Thu Aug 30 15:22:17 2012] [error] os.getcwd() = /
[Thu Aug 30 15:22:17 2012] [error] os.curdir = .
[Thu Aug 30 15:22:17 2012] [error] sys.path = ['/var/www/django/mysite/apache/..', '/usr/lib/python2.7/site-packages/rpy2-2.2.6dev_20120811-py2.7-linux-x86_64.egg', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/PIL', '/usr/lib64/python2.7/site-packages/gst-0.10', '/usr/lib64/python2.7/site-packages/gtk-2.0', '/usr/lib/python2.7/site-packages', '/usr/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info', '/var/www/django/mysite', '/var/www/django/static']
...
[Thu Aug 30 15:22:17 2012] [error] sys.modules.has_key('mysite') = True
[Thu Aug 30 15:22:17 2012] [error] sys.modules['mysite'].__name__ = mysite
[Thu Aug 30 15:22:17 2012] [error] sys.modules['mysite'].__file__ = /var/www/django/mysite/apache/../mysite/__init__.pyc
[Thu Aug 30 15:22:17 2012] [error] os.environ['DJANGO_SETTINGS_MODULE'] = mysite.settings
[Thu Aug 30 15:22:17 2012] [info] mod_wsgi (pid=14824): Create interpreter '127.0.0.1|'.
Here's django.wsgi. I used the version from django 1.4 but used the apache parallel directory as per your recommendations:
import os
import sys
#Takes advantage of setting up parallel file structure for mysite/apache/wsgi.py and mysite/mysite/settings.py
root = os.path.join(os.path.dirname(__file__), '..')
sys.path.insert(0, root)
#Seems to need the absolute path as well
sys.path.append('/var/www/django/mysite')
sys.path.append('/var/www/django/static')
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()
Any advice on why the static content isn't serving through mod_wsgi?
Thanks again for your help, this is great software!
Harry
On Tuesday, August 28, 2012 9:24:22 PM UTC-4, Graham Dumpleton wrote: