Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

/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>
share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

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

Try putting soemthing 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 soruce 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>
share|improve this answer
    
In the source on my html I see: href="/static/admin/css/base.css" but if I go to site.com/static/admin/css/base.css I see Not Found: The requested URL /static/admin/css/base.css was not found on this server. –  Fred Collins Apr 30 '11 at 23:20
    
So you need to tell apache that any requests to sent to /static/admin should be redirected to the path that is in the Alias in my post. Or what you could do is just copy /usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/ and name it "admin" inside your media folder –  Pratik Amin Apr 30 '11 at 23:41
    
If you make a folder on the level of settings.py call it static, and folder under it called admin and then put the admin media files in there it will work because apache can use that path. –  Pratik Amin May 1 '11 at 0:11
    
@Pratik Amin I'm gotta crazying. Should I run manage.py collectstatic ? –  Fred Collins May 1 '11 at 0:14
    
Personally when I have deployed Django I havent used the STATIC path stuff but just done it manually via a media directory inside the project folder. It looks like your regular site's media is already working. Did you try to add the alias? –  Pratik Amin May 1 '11 at 0:26
show 5 more comments

In Ubuntu 12.04.1 LTS Server you have to add this line:

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

in your Apache2 config or in VirtualHost.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.