1

I followed this guide to deploy Django + Nginx on Ubuntu 11.10. Django works well but Nginx doesn't serve any static files.

I'm trying to point app.com/static/ to local folder /project/app/static/

I've also tried everything in this question to no avail

Here is an excerpt from my settings.py:

STATIC_ROOT = ''

STATIC_URL = '/static/'

ADMIN_MEDIA_PREFIX = DOMAIN_URL + '/static/admin/'

STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, 'static'),
)

And from nginx.conf

server {
                listen 80;
                server_name localhost;
                # site_media - folder in uri for static files
                location /static/  {
                        autoindex on;
                        alias /project/app/static;
                        }
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|p$
  access_log   off; # po co mi logi obrazków :)
  expires      30d;
}
                location / {
                        # host and port to fastcgi server
                        fastcgi_pass 127.0.0.1:8080;
                        fastcgi_param PATH_INFO $fastcgi_script_name;
                        fastcgi_param REQUEST_METHOD $request_method;
                        fastcgi_param QUERY_STRING $query_string;
                        fastcgi_param CONTENT_TYPE $content_type;
                        fastcgi_param CONTENT_LENGTH $content_length;
                        fastcgi_pass_header Authorization;
                        fastcgi_intercept_errors off;
                        }

What do I do here?

Here's the nginx log

  WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!" while read$
2012/04/17 13:48:24 [error] 15598#0: *3 open() "/etc/nginx/html/static/css/rese$
2012/04/17 13:48:24 [error] 15598#0: *4 open() "/etc/nginx/html/static/images/l$
2012/04/17 13:48:24 [error] 15598#0: *5 open() "/etc/nginx/html/static/js/scrip$
2012/04/17 13:48:24 [error] 15598#0: *6 open() "/etc/nginx/html/static/js/jquery$
2012/04/17 13:48:24 [error] 15598#0: *7 open() "/etc/nginx/html/static/style.cs$
2012/04/17 13:48:24 [error] 15598#0: *8 open() "/etc/nginx/html/static/js/jquery$
2012/04/17 13:48:24 [error] 15598#0: *5 open() "/etc/nginx/html/static/images/i$
2012/04/17 13:48:24 [error] 15598#0: *7 open() "/etc/nginx/html/static/images/i$
2012/04/17 13:48:24 [error] 15598#0: *8 open() "/etc/nginx/html/static/images/i$
2012/04/17 13:48:24 [error] 15598#0: *6 open() "/etc/nginx/html/static/images/s$
2012/04/17 13:48:24 [error] 15598#0: *3 open() "/etc/nginx/html/static/images/s$
2012/04/17 13:48:24 [error] 15598#0: *4 open() "/etc/nginx/html/static/images/s$
2012/04/17 14:07:33 [error] 16231#0: *1 FastCGI sent in stderr: "WSGIServer: mi$
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!" while read$
2012/04/17 14:07:33 [error] 16231#0: *3 open() "/etc/nginx/html/static/css/rese$
2012/04/17 14:07:33 [error] 16231#0: *4 open() "/etc/nginx/html/static/style.cs$
2012/04/17 14:07:33 [error] 16231#0: *5 open() "/etc/nginx/html/static/js/jquery$
2012/04/17 14:07:33 [error] 16231#0: *6 open() "/etc/nginx/html/static/js/scrip$
2012/04/17 14:07:33 [error] 16231#0: *7 open() "/etc/nginx/html/static/js/jquery$
2012/04/17 14:07:34 [error] 16231#0: *7 open() "/etc/nginx/html/static/images/l$
2012/04/17 14:07:34 [error] 16231#0: *6 open() "/etc/nginx/html/static/images/i$
2012/04/17 14:07:34 [error] 16231#0: *4 open() "/etc/nginx/html/static/images/i$
2012/04/17 14:07:34 [error] 16231#0: *5 open() "/etc/nginx/html/static/images/i$
2012/04/17 14:07:34 [error] 16231#0: *3 open() "/etc/nginx/html/static/images/s$
2012/04/17 14:07:34 [error] 16231#0: *8 open() "/etc/nginx/html/static/images/s$
2012/04/17 14:07:34 [error] 16231#0: *5 open() "/etc/nginx/html/static/images/s$
2012/04/17 14:07:35 [error] 16231#0: *5 open() "/etc/nginx/html/static/images/f$
2012/04/17 14:10:30 [error] 16231#0: *9 FastCGI sent in stderr: "WSGIServer: mi$
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!" while read$
2012/04/17 14:11:57 [error] 16471#0: *1 FastCGI sent in stderr: "WSGIServer: mi$
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!" while read$

UPDATE:

SOLVED. I had not specified the what the root was in nginx.conf Once I did that, it all fell into place!

facepalm

 server_name localhost;
                root /home/user/projects;
                # site_media - folder in uri for static files
                location /static/  {

                        root /static/;
}
Community
  • 1
  • 1
slow_mondays
  • 871
  • 7
  • 19
  • This is not a Django issue. Rather, you have an nginx configuration problem. Check your nginx log files and see what the problem is. Post the errors here if you're having trouble understanding them. – Yuval Adam Apr 17 '12 at 14:07
  • If you have found the answer to your problem, you should post it as an answer instead of adding it to your question. – SingleNegationElimination Apr 17 '12 at 14:58
  • users with under 100 reputation can't post their own answer for 8hours (arbitrary i know) after they asked the question. hence the update. – slow_mondays Apr 17 '12 at 15:00
  • You actually could have stayed with the `alias`. Thats all I do in my nginx conf as opposed to setting the root again. – jdi Apr 17 '12 at 15:00

3 Answers3

1

It looks like nginx is serving the files, only they aren't there. This is because 1) you haven't specified a STATIC_ROOT and 2) you obviously haven't run collectstatic which would give you an error to that effect.

First, set:

STATIC_ROOT = '/project/app/static'

Or, for greater portability:

import os.path

STATIC_ROOT = os.path.join(os.path.dirname(__file__), 'static')

Then, run the following command on in your production environment:

python manage.py collectstatic
Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
1

I had not specified the what the root was in nginx.conf Once I did that, it all fell into place! facepalm

            server_name localhost;
            root /home/user/projects/;
            # site_media - folder in uri for static files
            location /static/  {

                    root /static/;}
slow_mondays
  • 871
  • 7
  • 19
-1

Django isn't actually designed to serve static files. They mention this many times throughout their docs. Simply use nginx to serve your static files separately, and then point django to that location.

Ash
  • 124
  • 6