[英]Django app not being served with Python3.5 and httpd
我在以下主机上托管了Django应用:
Server version: Apache/2.4.6 (CentOS)
Server built: Oct 19 2017 20:39:16
这是我的django.conf
文件:
Alias /static /home/faizan/myproject/static
<Directory /home/faizan/myproject/static>
Require all granted
</Directory>
<Directory /home/faizan/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-path=/home/faizan/myproject:/home/faizan/myproject/myprojectenv/lib/python3.5/site-packages
WSGIProcessGroup myproject
WSGIScriptAlias / /home/faizan/myproject/myproject/wsgi.py
当我在虚拟环境中安装python 2.7并安装了django.conf
时,我的应用程序正常工作:
Alias /static /home/faizan/myproject/static
<Directory /home/faizan/myproject/static>
Require all granted
</Directory>
<Directory /home/faizan/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-path=/home/faizan/myproject:/home/faizan/myproject/myprojectenv/lib/python2.7/site-packages
WSGIProcessGroup myproject
WSGIScriptAlias / /home/faizan/myproject/myproject/wsgi.py
带有mod_wsgi的Apache2,mod_wsgi二进制文件仅需针对一个Python版本进行编译,并且一次只能将已编译的mod_wsgi模块的一个实例加载到Apache中。
您使用python2.7安装了mod_wsgi,如果现在系统默认的python是python 3.5,则可以重新安装mod_wsgi(对于ubuntu,我不知道如何重新安装centos,但是您要做的就是用python重新安装mod_wsgi (必须与安装相同)与virtualenv一起使用):
sudo apt-get install libapache2-mod-wsgi-py3
如果系统默认的python不是python3.5,请从此处下载mod_wsgi,并使用在virtualenv中使用的python手动编译和安装(也适用于ubuntu):
tar xvfz mod_wsgi-X.Y.tar.gz
cd mod_wsgi-X.Y/
sudo ./configure --with-python=/usr/bin/python3.5
sudo make
sudo make install
sudo nano /etc/apache2/mods-available/wsgi.load
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so # write this to wsgi.load
sudo a2enmod wsgi
sudo service apache2 restart
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.