Python – Deploying Django with mod_wsgi

djangomod-wsgipython

/etc/apache2/site-available/mysite.com

<VirtualHost my_ip_here:80>
     ServerAdmin foo@mysite.com
     ServerName mysite.com
     ServerAlias www.mysite.com

     WSGIScriptAlias / /srv/www/mysite.com/djangoproject/django.wsgi

     <Directory "/srv/www/mysite.com/djangoproject/sitestatic">
        Order allow,deny
        Allow from all
     </Directory>

     AliasMatch /([^/]*\.css) /srv/www/mysite.com/djangoproject/sitestatic/css/$1
     AliasMatch /([^/]*\.js) /srv/www/mysite.com/djangoproject/sitestatic/js/$1

     Alias /media/ /srv/www/mysite.com/djangoproject/sitestatic/

     ErrorLog /srv/www/mysite.com/logs/error.log
     CustomLog /srv/www/mysite.com/logs/access.log combined
</VirtualHost>

/srv/www/mysite.com/djangoproject/settings.py

MEDIA_ROOT = ''

MEDIA_URL = '/media/'

STATIC_ROOT = '/srv/www/mysite.com/djangoproject/sitestatic/'

STATIC_URL = '/static/'

ADMIN_MEDIA_PREFIX = '/static/admin/'

Actually I see my site correctly with my css and images BUT when I go to /admin I see admin site without CSS. How can I fix? Also, it's correct my apache configuration for serving css and js and how can I hide the content of dir /media?

— SOLUTION (thanks to Pratik) —

Maybe, the problem is the order of lines in apache's config.

<VirtualHost my_ip_here:80>
     ServerAdmin foo@site.com
     ServerName site.com
     ServerAlias site.com

     DocumentRoot /srv/www/site.com/cherryproj/templates
     Alias /static/admin /usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/contrib/admin/media/
     Alias /static/ /srv/www/site.com/cherryproj/static/

     WSGIScriptAlias / /srv/www/site.com/cherryproj/django.wsgi
     <Directory "/srv/www/site.com/cherryproj/sitestatic">
        Order allow,deny
        Allow from all
     </Directory>

     ErrorLog /srv/www/site.com/logs/error.log
     CustomLog /srv/www/site.com/logs/access.log combined
</VirtualHost>

Best Answer

The admin media is actually located inside of Django's dist package.

Try putting something like this in Apache's config

Alias /static/admin "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/"

If that does not work view the page source while on the admin page, see the path that the css is trying to be loaded from and point Apache's alias to that path. It is probably a good idea to make a copy for this admin media outside of the dist-packages folder. Also your path is probably going to be different especially if you are using virutalenv.

To hide the contents of your media folder do

<Directory "/srv/www/mysite.com/djangoproject/sitestatic">
  Options -Indexes
  Order allow,deny
  Allow from all
  </Directory>
Related Topic