I am using Nginx to serve static files on django development server. However I can't make it work. The server runs fine but nginx is not able to find static files.
This is my settings in nginx.conf:
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#root html;
#index index.html index.htm;
proxy_pass http://127.0.0.1:8000;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
}
location /static/ {
alias /path/Documents/python_projects/to_pm/static/;
access_log off;
expires 30d;
}
My project settings.py:
STATIC_URL = '/static/'
# for production
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
And I have also used python manage.py collectstatics
to copy all static files to /path/Documents/python_projects/to_pm/static/
folder.
But when I use http://localhost:8080
the site comes up very ugly, clearly the static files are not serving by nginx. How can I fix this?
My error logs said
13: Permission denied` for static files
I check the users and see nginx is running under root as master process and nobody as worker process. I can't change user to root
and I can't change the user to my default user as I get this error if I change the user:
[emerg] getgrnam("root") failed in /usr/local/etc/nginx/nginx.conf:2