Gunicorn Setup
- Gunicorn is an application server (Nginx is serving proxy to Gunicorn)
sudo vim /etc/systemd/system/gunicorn.socket
[Unit] Description=gunicorn socket [Socket] ListenStream=/run/gunicorn.sock [Install] WantedBy=sockets.target
sudo vim /etc/systemd/system/gunicorn.service
[Unit] Description=gunicorn daemon Requires=gunicorn.socket After=network.target [Service] User=USERNAME Group=www-data WorkingDirectory=/home/USERNAME/MY_PROJECT_DIR ExecStart=MY_PROJECT_PATH/bin/gunicorn \ --access-logfile - \ --workers 3 \ --bind unix:/run/gunicorn.sock \ MY_PROJECT.wsgi:application [Install] WantedBy=multi-user.target
sudo systemctl start gunicorn.socket
sudo systemctl enable gunicorn.socket
sudo systemctl status gunicorn.socket
file /run/gunicorn.sock
, output should be: /run/gunicorn.sock: socket, if some issues, checksudo journalctl -u gunicorn.socket
and look at /etc/systemd/system/gunicorn.socket to fix some problemssudo systemctl status gunicorn
- Active: inactive (dead)curl --unix-socket /run/gunicorn.sock localhost
- output should be some htmlsudo systemctl status gunicorn
- Active: active (running), if some issues, checksudo journalctl -u gunicorn
and /etc/systemd/system/gunicorn.service and if you will make any changes, reload the daemonsudo systemctl daemon-reload
andsudo systemctl restart gunicorn
Resources:
➡️https://www.digitalocean.com/community/tutorials/how-to-deploy-a-local-django-app-to-a-vps
➡️http://rahmonov.me/posts/run-a-django-app-with-nginx-and-gunicorn/