Reputation: 55
Im trying to publish my Django project with NGINX and gunicorn, but I get permission denied from gunicorn.
My last steps what I did.
mkdir /home/sama/websites
cd /home/sama/websites
mkdir test_project
cd test_project
create Virtualenvirement for this project
virtualenv --python=/usr/bin/python3.8 venv
Virtualenvirement activate
source venv/bin/activate
Gunicorn & Django install
pip3 install gunicorn
pip3 install django
create project
cd ..
django-admin startproject config test_project
allow firewall to port 8000
sudo ufw allow 8000
run first test
python manage.py runserver 0.0.0.0:8000
open my server ip on webbrowser myIP:8000 I can see Django basic page
stop server CTRL + C
testGunicorn
gunicorn --bind 0.0.0.0:8000 config.wsgi
testagain on webbrowser Again I can see Djangos page
Server stop CTRL + C
exit virtualenvirement
deactivate
config Gunicorn create 2 files in /etc/systemd/system/
gunicorn.socket and gunicorn.service
edit this files
sudo nano /etc/systemd/system/gunicorn_test_project.socket
/etc/systemd/system/gunicorn.socket
[Unit]
Description=gunicorn daemon
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
/etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=sama
Group=www-data
WorkingDirectory=/home/sama/websites/test_project
ExecStart=/home/sama/websites/test_project/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock config.wsgi:application
[Install]
WantedBy=multi-user.target
test socket
sudo systemctl start gunicorn.socket
sudo systemctl enable gunicorn.socket
systemlink created, check it
file /run/gunicorn.sock
Output: /run/gunicorn.sock: socket
curl --unix-socket /run/gunicorn.sock localhost
And now I get permission denied
I already set permission for the folder test_project to user sama and group www-data, but without any effects. What is wrong?
Upvotes: 0
Views: 792
Reputation: 169051
I see no good reason to use systemd socket activation here.
Just use a service file and have Gunicorn bind to HTTP.
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=sama
Group=www-data
WorkingDirectory=/home/sama/websites/test_project
ExecStart=/home/sama/websites/test_project/venv/bin/gunicorn --access-logfile - --workers 3 --bind 0.0.0.0:8000 config.wsgi:application
[Install]
WantedBy=multi-user.target
Upvotes: 1