[Django]-Running Django Python Server in AWS

4👍

You can use either Apache or Nginx to deploy Django App. If you are planning to Use Nginx, first install Nginx in the server and add Django configurations to Nginx configuration. You can follow this as a good guide.

1👍

You can do it the hacky way: create a bash script that executes the app (just running the same command you execute to run it), and run the bash script with nohup, which detaches the process from the shell and will allow the application to continue running when you close your session:

nohup ./my_bash_script.sh &

If you want to do it properly, create a service file and execute the app as a service. You can create a simple service file like this:

[Unit]
Description=My Django app
After=network.target

[Service]
PIDFile=/run/DjangoApp/pid
User=<your user>
Group=<your group>
WorkingDirectory=<working directory of your Django app>
ExecStart=<path to your bash script>
PrivateTmp=True

[Install]
WantedBy=multi-user.target

Save the file under /etc/systemd/system/djangoService.service. You enable the service with this command:

sudo systemctl enable djangoService

And run it with this command:

sudo service start djangoService

That will keep the service running. Bear in mind, though, that to service a proper Django app you may want to use Gunicorn/wsgi to serve the responses, using Nginx to reverse proxy the requests.

1👍

In development mode, Django has a development server, which is sufficient for testing purposes. Once you complete a web application and it’s ready for production, the process of setting up the application on a server might be overwhelming for some, especially if you’re doing it for the first time. This article provides a step-by-step guide on how to deploy Django-based web applications using mod_wsgi.

You can follow this article for setting mod_wsgi with Apache server. enter link description here

If the one which you are setting up for development only then you need to run the server in daemon mode.

on Ubuntu

run:>./manage.py runserver 0.0.0.0:8000 > /dev/null 2>&1 &

>exit

1👍

Django runserver permanent
Hope this helps, it is the best way to create the screen so we can monitor what is happening and take the control back.

Leave a comment