-1

Static file can't serve via nginx. I didn't found any answer for this question so please help me to figure out.

settings.py

DEBUG = False

/etc/nginx/sites-available/example.com

upstream test {
        server 127.0.0.1:8000;
        keepalive 500;
}

server {

    listen   80;
    server_name example.com;

    client_max_body_size 4G; 
    location /static/ {
       alias   /home/user/live/staticfiles/;
   }

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header Host $http_host;

        proxy_redirect off;
             proxy_pass http://test;

    }

}

cat /var/log/nginx/error.log shows me below output

 2015/01/20 05:43:07 [error] 4480#0: *7 open() "/home/user/live/staticfiles/images/footer-logo.png" failed (13: Permission denied), client: 182.74.206.202, server: example.com, request: "GET /static/images/footer-logo.png HTTP/1.1", host: "example.com", referrer: "example.com/"

Update :

I just say it's not working ... Still getting same error i can't believe this happening because of file permission issue. I included below detail...

[myuserm@instance-4 home]$ namei -om /home/myuser/live/staticfiles/js/jquery.fancybox.js
f: /home/myuser/live/staticfiles/js/jquery.fancybox.js
 dr-xr-xr-x root          root          /
 drwxr-xr-x root          root          home
 drwxrwxrwx myuser        myuser        myuser
 drwxrwxrwx root          root          live
 drwxrwxrwx myuser        myuser        staticfiles
 drwxrwxrwx myuser        myuser        js
 -rwxrwxrwx myuser        myuser        jquery.fancybox.js
Booth
  • 211
  • 1
  • 2
  • 9
  • possible duplicate of [Nginx is throwing an 403 Forbidden on Static Files](http://stackoverflow.com/questions/20182329/nginx-is-throwing-an-403-forbidden-on-static-files) – Yogesh dwivedi Geitpl Jan 20 '15 at 10:17

1 Answers1

0

First of all you check your setting for static file that should look like this setting

STATIC_ROOT =  "/home/user/live/collected_static/"
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    PROJECT_DIR.child("static"),
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    #'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

then you run ./manage.py collectstatic # this will collect all static files to collected_static folder,

then in your nginx setting :

location /static {
    alias /home/user/live/collected_static/; 
}

   location / {

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        if (!-f $request_filename) {
            proxy_pass http://test;
            break;
        }
    }

Hope this will resolved your issue. and also check permission should we same as django project code. no need to give any extra permission.

For more setting and a very good doc you look here: Setting up Django with Nginx, Gunicorn, virtualenv, supervisor and PostgreSQL

For nginx permission issue you will find solution from these links:

Community
  • 1
  • 1
Yogesh dwivedi Geitpl
  • 4,252
  • 2
  • 20
  • 34