51
I had to change the permissions of my sock folder:
sudo chown ben:www-data /home/ben/myproject/
Another thing is that I have changed the sock location after reading in many post that itβs not a good pratice to keep the sock file in the django project.
My new location is:
/home/ben/run/
Donβt forget to change permissions:
sudo chown ben:www-data /home/ben/run/
To be sure that gunicorn is refreshed, run these commands:
pkill gunicorn
sudo systemctl daemon-reload
sudo systemctl start gunicorn
That will kill the gunicorn processes and start new ones.
You can run this command to make the process start at server boot:
sudo systemctl enable gunicorn
All works well now.
5
While the accepted answer works, there is one (imo major) issue with it, which is that the gunicorn web server is (probably) running as root, which is not recommended. The reason you end up needing to chown the socket is because it is owned by root:root
, because that is the user/group your init job assumes by default. There are multiple ways to get your job to assume another role. As of this time (with gunicorn 19.9.0), in my opinion, the simplest solution to this is to use the --user
and --group
flags provided as part of the gunicorn
command. This means your server can start with the user/group you specify. In your case:
exec gunicorn --user ben --group www-data --bind unix:/home/ben/myproject/myproject.sock -m 007 wsgi
will start gunicorn under ben:www-data
user and create a socket owned by ben:www-data
with the permissions 770
, or read/write/execute privilege for the user ben
and group www-data
on the socket, which is exactly what you ned in this case.
- [Django]-How can I get MINIO access and secret key?
- [Django]-Get the list of checkbox post in django views
- [Django]-How does django handle multiple memcached servers?
0
I have given path to the sock file outside my project. I needed to just create the directory so that the gunicorn can create the file inside that directory as I had had mentioned that path in the .services file. Basically, I made sure that I had all directories existing according to the path in the .services file. No need to change permissions or ownership
- [Django]-How to serve media files on Django production environment?
- [Django]-Django Sitemaps and "normal" views
- [Django]-How do I get the class of a object within a Django template?
-2
Try run
sudo systemctl daemon-reload
sudo systemctl start gunicorn
sudo systemctl status gunicorn.service
The last line helped me to re-create .scok file
- [Django]-Get list item dynamically in django templates
- [Django]-Django Multiple Authentication Backend for one project
- [Django]-Ignoring Django Migrations in pyproject.toml file for Black formatter