【问题标题】:How to set the apache2.conf file for a django project?如何为 django 项目设置 apache2.conf 文件?
【发布时间】:2018-12-25 02:55:48
【问题描述】:

我现在在 aws-ec2 上部署一个 django 测试项目,AMI 是 Ubuntu18.04,带有 Python 3.6、Django 2.1、Apache2。

该项目位于 /var/www/Project 下,我正在尝试将设置添加到 apache.conf。

该项目只是由 django-admin startproject 项目生成的,我想确保当点击实例提供的公共 IP 时,它应该显示 django 默认页面。

WSGIDaemonProcess ubuntu  processes=2 threads=12 python-path=/var/www/Project
WSGIProcessGroup ubuntu
WSGIRestrictEmbedded On
WSGILazyInitialization On
WSGIScriptAlias / /var/www/Project/Project/wsgi.py

<Directory /var/www/Project/Project>
    Require all granted
</Directory>

现在我收到了内部服务器错误。

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

我以前试过这个。它似乎只在我将 python2.7 与 django 1.11 一起使用时才有效。

WSGIScriptAlias / /var/www/Project/Project/wsgi.py

WSGIPythonPath /var/www/Project

<Directory /var/www/Project/Project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

我的 conf 文件有什么问题?

【问题讨论】:

标签: django apache amazon-web-services ubuntu amazon-ec2


【解决方案1】:

我终于想出了以下解决方案。

如果您使用的是 Apache2、Python2 和 Ubuntu18.04 LTS,您可以通过添加以下内容来更改 apache2.conf 文件:

WSGIScriptAlias / [path_to_wsgi.py]

WSGIPythonPath [path_to_project]

<Directory [path_to_project]>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

如果您想使用最新的 Django 2+ 版本,请更改 /etc/apache2/sites-available/000-default.conf,这是 HTTP 端口 80 的设置。(000-default.conf 文件不能包含虚拟主机中的 WSGIPythonPath)

<VirtualHost *:80>
ServerAdmin webmaster@localhost
Alias /static [path_to_static_folder]

<Directory [path_to_static_folder]>
Require all granted
</Directory>

<Directory [path_to_project]>
<Files wsgi.py>
    Require all granted
</Files>
</Directory>

WSGIDaemonProcess [name] python-home=[path_to_virtualenv] python-path=[path_to_project]
WSGIProcessGroup [name]
WSGIScriptAlias / [path_to_project_wsgi.py]

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-03
    • 1970-01-01
    • 2022-10-14
    • 1970-01-01
    • 1970-01-01
    • 2011-09-05
    • 2010-12-11
    • 2018-08-03
    相关资源
    最近更新 更多