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.

First, I want to clarify that this error is just for the admin static files. This means my problem is specific just to the static files that corresponds to the Django admin. The rest of the static files are working perfect.

Basically my problem is that for some reason I cannot access those admin static files with the ngix server.

It works perfect with the micro server of Django and the collect static is doing its job. This means it is putting the files on the expected place in the static folder.

The urls are correct but I cannot even access the admin static files directly, but the others I can. So, for example,

  1. I am able to access this url (copying it in the browser): myserver.com:8080/static/css/base/base.css

  2. but i am not able to access this other url (copying it in the browser): myserver.com:8080/static/admin/css/admin.css

I also tried to copy the admin/ directory structure into other_admin_directory_name/. Then I can access myserver.com:8080/static/other_admin_directory_name/css/admin.css

Then, it works. So,

  1. I checked permissions and everything is fine.
  2. I tried to change ADMIN_MEDIA_PREFIX = '/static/admin/' to ADMIN_MEDIA_PREFIX = '/static/other_admin_directory_name/', it doesn't work. This a mistery in itself that I am exploring but still no luck.

Finally, and it seems to be an important clue:

I tried to copy the admin/ directory structure into admin_and_then_any_suffix/. Then I cannot access myserver.com:8080/static/admin_and_then_any_suffix//css/admin.css

So, if the name of the directory starts with admin (for example administration or admin2) it doesn't work.

* added thanks to sarnold observation ** the problem seems to be in the nginx configuration file /etc/nginx/sites-available/mysite

location /static/admin {
   alias /home/vl3/.virtualenvs/vl3/lib/python2.7/site-packages/django/contrib/admin/media/;
}
share|improve this question

migrated from stackoverflow.com Jun 29 '12 at 1:50

This question came from our site for professional and enthusiast programmers.

2  
You forgot to include the relevant portions of your nginx configuration. –  sarnold Jun 27 '12 at 23:27
    
This is a clean ubuntu 11.10 installation (it was working before in the same clean version) and I haven't touch the conf file but it seems you are right. There is something that seems to be the problem. I am editing my question... –  toto_tico Jun 28 '12 at 0:03
    
@Carsten, maybe your link is wrong. [link](serveroverflow.com) does not exist –  toto_tico Jun 28 '12 at 0:13
    
Is there a reason you need a specific location entry just for /static/admin? Wouldn't the standard '/static' cover it all? I just use a single: location /static/ { alias /path/to/static/; } –  jdi Jun 28 '12 at 0:18
    
ok, i did the obvious here. I changed the path to the exact directory I have the files. It worked but I am worried, I don't think that is a line I should arbitrary change. This is a default configuration. I'll let you know exactly what is happening. Thanks! –  toto_tico Jun 28 '12 at 0:25
show 2 more comments

1 Answer

up vote 6 down vote accepted

My suggestions:

  1. Use django 1.3+ (and ADMIN_MEDIA_PREFIX is deprecated now)

  2. Set both STATIC_URL and STATIC_ROOT in your settings.py

  3. Define just a single static entry in your nginx conf (with trailing slashes). No need for a second one that addresses static/admin/:

    location /static/  {
            alias /path/to/static/;
    }
    
  4. Use collectstatic which should collect admin -> static/admin. It will live under the same location as all the rest of your collected static media.

    python manage.py collectstatic

share|improve this answer
    
I am using django 1.4. I have the three of them: ADMIN_MEDIA_PREFIX, STATIC_URL, STATIC_ROOT. The collectstatic is working well as I explained. The only thing I am still curious about is where that ...python2.7/site-packages/...static/ came from... –  toto_tico Jun 28 '12 at 0:36
1  
Well you can get rid of ADMIN_MEDIA_PREFIX. Its no longer in use. That and the reference to the site-packages is all OLD django stuff. Its not used in 1.3+. admin will end up in the static root. –  jdi Jun 28 '12 at 0:37
    
perfect! As I said this was a clean ubuntu 11.10 / nginx installation. Do you mind to do a small edition in your answer adding another step: delete the location /static/admin/ { ... } section –  toto_tico Jun 28 '12 at 0:41
    
Why? Did your default nginx conf somehow come with that entry in the first place? I was listing sort of a ground up set of items that would apply to anyone. If it isn't there then you probably shouldn't have it. –  jdi Jun 28 '12 at 0:51
    
well, that's exactly what i mean. This is a clean installation. I never touched that file before. I solved the problem deleting that section in the file. –  toto_tico Jun 28 '12 at 1:10
add comment

Your Answer

 
discard

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