miki725
miki725

Reputation: 27861

Deploying Django with Nginx as service

Currently I have a home server (Ubuntu) with nginx running where I use proxy pass in order to pass the requests to django. I am using gevent as my wsgi server.

It all works fine until the server shuts down either because I restart the server for whatever reason or something crashes (electricity). Since nginx is a service, when the server restarts, nginx starts up as well. However my django apps do not. So then I have to manually go to each of my django projects, activate their virtualenvs, and then fire up the gevent process. This is very annoying to say the least.

Is there a standard way of handling all of this automatically?

Upvotes: 1

Views: 364

Answers (2)

Burhan Khalid
Burhan Khalid

Reputation: 174624

Consider using a process manager to handle this for you. I like supervisor

You tell it how to launch your various processes and then it runs in the background (just like nginx) and will automatically start up on restart and launch your various django backend processes.

Upvotes: 1

Chris Pratt
Chris Pratt

Reputation: 239250

You need to set up a script for something like Upstart or Supervisor. Personally, I prefer using Supervisor. Here's the script I use to run my gunicorn instances:

[program:gunicorn]
command=/path/to/virtualenv/bin/python manage.py run_gunicorn -c /path/to/gunicorn.conf.py
directory=/path/to/django/project
user=www-data
autostart=true
autorestart=true
redirect_stderr=True

Upvotes: 7

Related Questions