Django + Gunincorn - deploy and stay connected to the port?

102 Views Asked by At

Correct me if I am wrong: I can use gunicorn to deploy a django project, for instance I can deploy my app - helloapp in this way:

$ cd env
  $ . bin/activate
  (env) $ cd ..
  (env) $ pip install -r requirements.txt
  (env) root@localhost:/var/www/html/helloapp# gunicorn helloapp.wsgi:application
  [2017-05-18 22:22:38 +0000] [1779] [INFO] Starting gunicorn 19.7.1
  [2017-05-18 22:22:38 +0000] [1779] [INFO] Listening at: http://127.0.0.1:8000 (1779)
  [2017-05-18 22:22:38 +0000] [1779] [INFO] Using worker: sync
  [2017-05-18 22:22:38 +0000] [1783] [INFO] Booting worker with pid: 1783

So now my django site is running at http://127.0.0.1:8000.

But it will not be available anymore as soon as I close/ exit my terminal. So how can I have it stayed connected to the port 8000 even if I have closed my terminal?

1

There are 1 best solutions below

3
On

As with any long-running process, you need to run it as a service under some kind of manager. Since you're on Ubuntu, you probably want to use systemd; full instructions are in the gunicorn deployment docs. Note, you will also need to configure nginx as a reverse proxy in front of gunicorn.