Django nginx admin media
I am currently testing moving from Apache mod_wsgi
to Nginx and FastCGI
I have prepared the whole installation and currently开发者_开发技巧 testing it on a CentOS 5.4 box
that runs Django 1.1.2
In my old Apache configuration
I had and alias setup for /media/
and also one called /mediaadmin/
Which is displayed below.
Alias /media/ "/www/django_test1/omu2/media/"
<Directory "/www/django_test1/omu2/media">
Alias /mediaadmin/ "/opt/python2.6/lib/python2.6/site-packages/django/contrib/admin/media/"
<Directory "/opt/python2.6/lib/python2.6/site-packages/django/contrib/admin/media">
How do I get the same type of setup for Nginx configuration, currently here is a snippet of what I have, even after restarting Nginx i still don't see my admin side resolving with the correct CSS, images etc.
server {
location /media/ {
root /www/django_test1/omu2;
}
location /mediaadmin/ {
root /opt/python2.6/lib/python2.6/site-packages/django/contrib/admin;
}
}
My settings.py
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
BASE_URL = '127.0.0.1'
MEDIA_ROOT = "%s/media/" % BASE_PATH
MEDIA_URL = "%s/media/" % BASE_URL
ADMIN_MEDIA_PREFIX = "%s/mediaadmin/" % BASE_URL
Try the following config:
location /mediaadmin/ {
alias /opt/python2.6/lib/python2.6/site-packages/django/contrib/admin/media/;
expires max;
add_header Cache-Control public;
}
I changed the path to /django/contrib/admin/media/
as I guess our admin media files are in this folder as normal.
Hint: your MEDIA_ROOT
and ADMIN_MEDIA_PREFIX
sould be absolute.
I also found that the following line caused a lot of confusion
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov) {
access_log off;
expires 30d;
}
I commented this out, and changed /mediaadmin/ from root to alias instead.
精彩评论