1

I am trying to configure Nginx with uWSGI to serve Django app but the layout of admin panel is distorted totally...

Here is my Nginx configuration:

upstream django {
    server 127.0.0.1:8000;
    }

server {
    # the port your site will be served on
    listen      4321;
    # the domain name it will serve for
    server_name localhost;
    charset     utf-8;
    access_log /var/log/nginx/local-access.log;
    error_log /var/log/nginx/local-error.log;

    client_max_body_size 75M; 

    location /static/admin {

    alias /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;
    }

    location / {
    uwsgi_pass  django;
    include     /etc/nginx/uwsgi_params;
    }

}

here is the Nginx error: 2013/05/13 18:13:26 [error] 12491#0: *255 open() "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin/js/ddsmoothmenu.js" failed (2: No such file or directory)

access logs:

[pid: 6848|app: 0|req: 8/13] 127.0.0.1 () {42 vars in 773 bytes} [Tue May 14 12:59:30 2013] GET /admin/ => generated 1960 bytes in 995 msecs (HTTP/1.1 200) 7 headers in 438 bytes (1 switches on core 0)
[pid: 6847|app: 0|req: 3/14] 127.0.0.1 () {44 vars in 858 bytes} [Tue May 14 12:59:32 2013] GET /admin/brightCouponsApp/static/admin/css/login.css => generated 0 bytes in 28 msecs (HTTP/1.1 500) 1 headers in 78 bytes (1 switches on core 0)

The static files which belongs to my Django App are working fine but Django admin layout is not can some one help me out...

1
  • There is my app name in between admin and static why is that /admin/brightCouponsApp/static/admin/css/login.css i think it should be /admin/static/admin/css/login.css Commented May 14, 2013 at 8:13

1 Answer 1

4

Check out the collectstatic command instead of serving files from your site-packages directory. The management command will basically copy static files from all your apps into STATIC_ROOT.

Sign up to request clarification or add additional context in comments.

3 Comments

Already did..not working i have another app that has similar configuration but that works fine...no idea what happening...
The reason your configuration does not work might be that root owns the django files in site-packages and hopefully you do not run your nginx workers as root. That is the reason why I suggested to use collectstatic. In order to get it to work you should remove location /static/admin {...} from nginx config and add config for location /static {} pointing to STATIC_ROOT.
I tried that to ....i used /static for my app as well it is working fine but again the static files for Django are unable to load ....actually nginx is able to find but 500 error is thrown .....this time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.