Errno 13 Permission denied using Gunicorn
This all depends on the user that your application is running as.
If you check ps aux | grep gunicorn
which user the Gunicorn server is running your app as then you can change the chmod
or chown
permissions accordingly.
ls -lash
will show you which user current only owns the folder and what permissions are on the folder you are trying to write to:
4.0K drwxrwx--- 4 username username 4.0K Dec 9 14:11 uploads
You can then use this to check for any issues.
Some docs on changing ownership and permissions
http://linux.die.net/man/1/chmod
http://linux.die.net/man/1/chown
I would advise being very careful to what locations on your disk you give access for the web server to read/write from. This can have massive security implications.
Well, I worked on this issue for more than a week and finally was able to FIGURE IT OUT. Please follow links from digital ocean , but they did not pinpoint important issues one which includes
- no live upstreams while connecting to upstream
- *4 connect() to unix:/myproject.sock failed (13: Permission denied) while connecting to upstream
- gunicorn OSError: [Errno 1] Operation not permitted
*1 connect() to unix:/tmp/myproject.sock failed (2: No such file or directory)
etc.
These issues are basically permission issue for connection between Nginx and Gunicorn. To make things simple, I recommend to give same nginx permission to every file/project/python program you create.
To solve all the issue follow this approach: First thing is :
- Log in to the system as a root user
- Create /home/nginx directory.
- After doing this, follow as per the website until Create an Upstart Script.
- Run chown -R nginx:nginx /home/nginx
- For upstart script, do the following change in the last line : exec gunicorn --workers 3 --bind unix:myproject.sock -u nginx -g nginx wsgi DONT ADD -m permission as it messes up the socket. From the documentation of Gunicorn, when -m is default, python will figure out the best permission
- Start the upstart script
Now just go to /etc/nginx/nginx.conf file. Go to the server module and append:
location / { include proxy_params; proxy_pass http<>:<>//unix:/home/nginx/myproject.sock; } REMOVE <> Do not follow the digitalocean aricle from here on
- Now restart nginx server and you are good to go.