1

I am trying to setup a django production server on OSX (Mavericks).

This is my nginx server config file:

server { 
    listen       80;
    server_name  localhost;
    error_log   /pathtoerrorlog;
    access_log  /pathtoaccesslog;

    # serve static files
    location ~ ^/static/  {
      root    /Users/Hello/assets;
      expires 30d;
    }

    # serve media files ~ ^
    location ~ ^/media/  {
      root    /Users/Hello/assets;
      expires 30d;
    }

    location / {
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Real-IP $remote_addr;    
      proxy_pass http://localhost:8000;
    }
  }

This is the nginx.conf config file

user www-data;
worker_processes  4;

error_log   /var/log/nginx/error.log;

events {
    worker_connections  4092;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay on;

    keepalive_timeout  65;

    types_hash_max_size 2048;
    server_names_hash_bucket_size 64;

    gzip  on;
    gzip_disable "msie6";

    include /etc/nginx/sites-enabled/*;

}

I have created a user called www-data on the system and gave the folllowing access permissions:

sudo chown -R www-data:www-data /usr/local/etc/nginx
sudo chown -R www-data:www-data /etc/nginx
sudo chown -R www-data:www-data /var/log/nginx

I started gunicorn without any errors and so is the case with nginx too.

In a browser, localhost redirects me to the django app but static media is not displayed. This is a sample error (out of all for static content) I get, as I see in nginx error log:

2014/01/25 20:16:23 [error] 35068#0: *68 open()    "/Users/Hello/assets/static/css/base.css" failed (13: Permission denied), 
client: 127.0.0.1, server: localhost, request: "GET /static/css/base.css HTTP/1.1", host: "localhost", referrer: "http://localhost/" 

I tried changing the permissions of /Users/Hello/assets using sudo chown -R www-data:www-data assets but it didn't help. -R 777 also didn't work.

Please suggest where I am going wrong. Thanks!

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
hekum
  • 21
  • 4

1 Answers1

1

It turns out to be that read permissions have to be granted for all parent directories of /Users/Hello/assets. So, I set read access to all of Users, Hello, assets and not just assets as earlier.

Related articles are :

Nginx 403 forbidden for all files

http://nginxlibrary.com/403-forbidden-error/

Community
  • 1
  • 1
hekum
  • 21
  • 4