如何为django项目设置apache2.conf文件



我现在正在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文件怎么了?

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

如果您使用的是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文件无法在VirtualHost中包含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>

最新更新