使用 Apache Web 服务器配置 Django

2024年8月29日 | 1 分钟阅读

Django 使用其内置的开发服务器来运行 Web 应用程序。要启动此服务器,我们可以使用 python manage.py runserver 命令。

此命令启动服务器,该服务器在端口 8000 上运行,可以通过在浏览器中输入 *localhost:8000* 来访问。 它显示应用程序的欢迎页面。

django configuration with apache web server

并且在浏览器中,可以如下方式访问。

django configuration with apache web server 1

但是,如果我们希望使用 apache server 而不是内置开发服务器来运行我们的应用程序,则需要配置位于 /etc/apache 目录下的 apache2.conf 文件。 将以下代码添加到此文件中。

// apache2.conf

添加这些行后,使用 service apache2 restart 命令重新启动 Apache 服务器,然后在浏览器的地址栏中键入 localhost。 这一次,项目将在 Apache 服务器而不是内置服务器上运行。 看到,它显示了应用程序的主页。

django configuration with apache web server 2
下一个主题虚拟环境设置