使用 Django Dev Server 托管 Public 个网站

Hosting Public websites with Django Dev Server

我正在尝试托管我的个人网站,我是托管网站业务的新手,所以这可能是一个菜鸟问题。

所以我使用 django 制作了我的网站,并在本地测试了所有内容。现在我想制作网站 public,然后我遇到了这个: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Deployment 这似乎是一个痛苦的屁股。

但是,然后我想我可以使用以下方法使该网站在所有界面上可用:

python manage.py runserver 0.0.0.0:80 Now I can access the website using http://myIp/myapp

所以我的问题是,"Is it a good idea to host websites using the django dev server"

直觉是一个"No",但我很想知道"Why?"

你的直觉是对的。您最好使用将为您的 Django 应用程序提供服务的 WSGI 服务器。 配置起来并不难。

我个人喜欢使用 Gunicorn,它易于设置。设置可能如下所示:

gunicorn mirador_django.wsgi:application \
  --bind 0.0.0.0:8000 \
  --workers 4

(参见:http://docs.gunicorn.org/en/latest/run.html

然后我在我的 Web 服务器上设置了一个反向代理以指向 Gunicorn。对于 Nginx,信息在 gunicorn 网站上:http://gunicorn.org/#deployment 您也可以像我目前所做的那样轻松地在 apache 服务器上进行设置。

希望对您有所帮助。

您可以使用 Apache,它很简单,并且有很多关于 django 和 apache 的启动指南,甚至在 django 文档中也是如此。