Serve a Django application using Gunicorn

Create systemd service file vi /usr/lib/systemd/system/backend.service Add [Unit] Description=Gunicorn instance to serve Django Application After=network.target [Service] User=www-data Group=www-data Environment=”APP=app” WorkingDirectory=/path/to/app/backend Environment=”PATH=/path/to/app/backend/venv/bin” ExecStart=/path/to/app/backend/venv/bin/gunicorn -w 3 –timeout 120 –bind 0.0.0.0:8080 backend.wsgi [Install] WantedBy=multi-user.target On the above, you need to replace “/path/to/app/backend” with the path to your application. In backend.wsgi, backend is the application name here, change it … Read more

Running Python Application with gunicorn and nginx

Create a service file for gunicorn root@django:~# cat /etc/systemd/system/gunicorn2.service [Unit] Description=gunicorn2 daemon Requires=gunicorn2.socket After=network.target [Service] User=ubuntu Group=www-data WorkingDirectory=/home/ubuntu/myapp/wagtail2 ExecStart=/home/ubuntu/myapp/venv/bin/gunicorn \ –access-logfile – \ –workers 3 \ –bind unix:/run/gunicorn2.sock \ wagtailblog4.wsgi:application [Install] WantedBy=multi-user.target root@django:~# Here /home/ubuntu/myapp/wagtail2 = path to the folder where web application is. /home/ubuntu/myapp/venv/bin/gunicorn = is where gunicorn installed inside virtualenv. Change these path … Read more

gunicorn behind Apache web server

gunicorn is a python application server used to run python applications in production. This is normally run behind web servers like nginx or apache. To configre gunicorn behind apache, enable following apache modules. a2enmod proxy proxy_ajp proxy_http rewrite deflate headers proxy_balancer proxy_connect proxy_html xml2enc Restart apache web server systemctl restart apache2 For web site running … Read more