I have set up a VPS and installed Django on it.
I've installed Django within the virtual environment i created using python3 -m venv env
and activated via source env/bin/activate
.
In order to run the Django built-in webserver i need to run python3 manage.py runserver
.
The webserver runs until i close the SSH session, so how can i run a standalone webserver without being dependent on the SSH session. (And also taking advantage of being ran inside the virtual environment)?
CodePudding user response:
One of the simplest way to do this is use docker. Example how to setup docker with django: https://docs.docker.com/samples/django/
Or you can solve this with screen in linux system, but remember this is not for production use: https://linuxhint.com/screen_command_ubuntu/
CodePudding user response:
Running it as a background process is a quick solution.
nohup python3 manage.py runserver &
If you really want to take it to next level then consider running it using one of the Django deployment options which are very well documented by Django team.
https://docs.djangoproject.com/en/4.0/howto/deployment/
I have used Gunicorn with nginx server running to front it so that nginx can server static content. you can find details here.
https://docs.gunicorn.org/en/stable/deploy.html#using-virtualenv