简体   繁体   中英

How to keep django rest API server running automatically on AWS?

So I uploaded my Django API with Rest framework on AWS EC2 instance. However, I have to manually go to Putty and connect to my EC2 instance and turn API on whenever I want to use it by inputting python manage.py runserver 0.0.0.0:8000 .

When I turn off my PC, putty closes and API cannot be accessed anymore on the ip address.

How do I keep my API on forever? Does turning it into https help? Or what can be done?

You can make it live always by following means,

  • connect your ec2 instance using ssh.
  • Then deploy your backend (django) on that instance and run it at any port.
  • Once run on your desired port, you can close the terminal, please don't press ctrl+c so that your django server does not stop. you can just cross the terminal. it will be now running.

You can also run the django server on tmux (its terminal inside terminal). here is tutorial on tmux. https://linuxize.com/post/getting-started-with-tmux/

One other approach is, you can deploy the django using docker container.

I hope you will come over your problem.

Thanks.

Ok I finally solved this. So when you close putty or a ssh client session, the session goes offline. However, if you run the session via daemon, the session continues in the background even when you close your clients. The code is

$ nohup python ./manage.py runserver 0.0.0.0:8000 & 

Of course you can use tmux or docker, as suggested by madi, but I think running this one code is much simpler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM