【问题标题】:How to run the django web server even after closing the shell on Amazon Linux即使在 Amazon Linux 上关闭 shell 后如何运行 django Web 服务器
【发布时间】:2018-05-10 21:21:22
【问题描述】:

我正在使用以下命令在我的 Amazon Linux 实例上运行 Django 应用程序:

python manage.py runserver ec2-instance-ip.us-east-2.compute.amazonaws.com:8000

我希望应用程序即使在我退出 shell 后也能运行。即使在 Amazon Linux 上退出 shell 后,我如何运行此 Web 服务器?

我尝试使用如下所示的&,但没有成功。

python manage.py runserver ec2-instance-ip.us-east-2.compute.amazonaws.com:8000 &

【问题讨论】:

标签: django linux python-2.7 amazon-web-services


【解决方案1】:

使用以下命令安装屏幕 Screen 基本上是一个始终运行进程的工具,即使我们退出。

sudo apt-get update
sudo apt-get install screen

详情可以看:https://www.digitalocean.com/community/tutorials/how-to-install-and-use-screen-on-an-ubuntu-cloud-server

为您的命令创建一个屏幕,以便您的命令可以作为守护程序运行。

screen -S <processName> //Process name could be any random name for your process.

进入内屏。

screen -r <processName> 

现在您在屏幕内,可以在这里运行您的命令。

python manage.py runserver ec2-instance-ip.us-east-2.compute.amazonaws.com:8000

现在退出屏幕:ctrl+a and then d

您可以根据需要创建多个屏幕,并且可以随时通过命令列出它们:

screen -ls

!important:不建议将其用于生产服务器。 看看这个在生产服务器上运行 Python 应用程序:https://docs.djangoproject.com/en/2.0/howto/deployment/

【讨论】:

  • 为我工作。谢谢!
【解决方案2】:

运行python manage.py ... 是您在开发中运行的方式,但不是在Web 服务器上运行的方式。您需要部署您的应用程序。

看看Apache and mod_wsgi

【讨论】:

    猜你喜欢
    • 2013-04-21
    • 2012-12-28
    • 2016-04-20
    • 1970-01-01
    • 2012-05-26
    • 1970-01-01
    • 2013-01-25
    • 2012-11-11
    • 1970-01-01
    相关资源
    最近更新 更多