0

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?

Run
  • 54,938
  • 169
  • 450
  • 748

1 Answers1

0

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.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • how can I use Apache instead? – Run May 19 '17 at 09:38
  • If you want to use Apache, you should use its mod_wsgi plugin rather than gunicorn. Once again, there is full documentation both [in the Django docs](https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/modwsgi/) and on [modwsgi's own site](https://modwsgi.readthedocs.io/en/develop/). – Daniel Roseman May 19 '17 at 09:40
  • for my own projects in the future i would use mod_wsgi plugin rather than gunicorn. I have this legacy django project that i am taking over which is using gunicorn. – Run May 19 '17 at 09:43