Setup multiple django gunicorn instances with nginx - python

Got one django site running with gunicorn & nginx need to setup another site also with the same. Nginx settings is straight forward, how to rework below to add another site /home/ubuntu/webapps/uganda_buzz/
relevant settings are /etc/init/gunicorn.conf
description "Gunicorn application server handling all projects"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
setuid user
setgid www-data
chdir /home/ubuntu/webapps/kenyabuzz
exec /home/ubuntu/webapps/djangoenv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/webapps/kenyabuzz/kb.sock kb.wsgi:application
and /etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=ubuntu
Group=nginx
WorkingDirectory=/home/ubuntu/webapps/kenyabuzz
ExecStart=/home/ubuntu/webapps/djangoenv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/webapps/kenyabuzz/kb.sock kb.wsgi:application
[Install]
WantedBy=multi-user.target

Try How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 14.04 LTS
or Configuring multiple domains and subdomains. DNS & Nginx issues abound!

Related

Failed at step EXEC spawning /var/www/loveIt/env/bin/gunicorn: No such file or directory

I have a problem with gunicorn. I followed this guide to run website hosting on my raspberry on debian. But I got this error:
gunicorn.service: Failed at step EXEC spawning /var/www/loveIt/env/bin/gunicorn: No such file or directory
I don't understand why it don't create gunicorn. I watched a lot of guides but no one helped me. Here is my gunicorn.service file:
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=anton
Group=www-data
WorkingDirectory=/var/www/loveIt
ExecStart=/var/www/loveIt/env/bin/gunicorn \
--access-logfile - \
--workers 5 \
--bind unix:/run/gunicorn.sock \
lulu.wsgi:application
[Install]
WantedBy=multi-user.target
And this is my gunicorn.socket file:
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
What I need to do to solve this problem?

Custom service created using gunicorn in Ubuntu is throwing Error but Gunicorn funtion alone works perfectly fine

Having Issue with Service that i Created.
gunicorn –bind 0.0.0.0:5000 wsgi:application
This works well no issue at all
but with the Service… i get error
[Unit]
Description=Gunicorn instance to serve lolf
Wants = network-online.target
After = network.target network-online.target
[Service]
User=lolfbwu1
Group=www-data
WorkingDirectory=/home/lolfbw/lolf
Environment=“PATH=/home/lolfbw/lolf/lolfenv/bin”
ExecStart=/home/lolfbw/lolf/lolfenv/bin/gunicorn –workers 3 –bind unix:lolf.sock -m 007 wsgi
[Install]
WantedBy=multi-user.target
Error i am getting:
gunicorn[27945]: finalstart =
datetime.fromisoformat(formatedstart).timestamp()
gunicorn[27945]: ValueError: Invalid isoformat string: ’ 00:00:00’
But i don’t get this error when running it as
gunicorn –bind 0.0.0.0:5000 wsgi:application
Any Idea why is that…?
I am using Python3.9

Publish Django project with gunicorn and NGINX

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?
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

nginx+uwsgi+django emperor mode not working

I am doing multi-application nginx+uwsgi setup in django. I am following this documentation
to set up emperor mode for my project.
It works fine when I run "uwsgi --ini myproject_uwsgi.ini" but I am not able to deploy emperor mode following this documentation.
I have researched many docs but not able to find relevant information related to emperor mode setup.
My nginx.conf file:(angularJS frontend)
server {
listen 80;
server_name 192.168.xx.xx;
root /home/user/Myspace/workspace/Myproject_frontend/dist;
}
My "etc/uwsgi/vassals/uwsgi.ini" file looks like:
[uwsgi]
#Django-related settings
#Django's wsgi file
wsgi-file = /home/user/Myspace/workspace/myproject/myproject/wsgi.py
http = 192.168.xx.xx:8080
virtualenv = /home/user/Myspace/VENV_MYPROD
Also, i have created a uwsgi.service file in "/etc/systemd/system/uwsgi.service" to start emperor mode service and it looks like:
[Unit]
Description=uWSGI Emperor service
After=syslog.target
[Service]
ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals/
RuntimeDirectory= uwsgi
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all
[Install]
WantedBy=multi-user.target
Please provide help on setting up uwsgi emperor mode.

Unable to start gunicorn.service due to import module error

I am trying to start Gunicorn from systemd service file, but I get import module error. How can I fix it?
My gunicorn service file:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/sammy/myproject
ExecStart=/home/sammy/myproject/venv/bin/gunicorn --workers 3 --bind unix:/home/sammy/myproject/myproject.sock myproject.wsgi:application
[Install]
WantedBy=multi-user.target
When I execute gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application, there is no error.
But when I use
sudo systemctl start gunicorn
sudo systemctl enable gunicorn
I get this error:
ImportError: No module named 'myproject'
What is wrong?
It is probably a directory permission problem. Make sure the user sammy is in the www-data group and set the home directory permissions with a chmod 710.

Categories