Django应用程序没有使用Python3.5和httpd

时间:2018-02-08 07:17:49

标签: python django python-3.x apache server

我有一个主持的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

1 个答案:

答案 0 :(得分:1)

使用mod_wsgi的Apache2,mod_wsgi二进制文件必须仅针对一个Python版本进行编译,并且一次只能将一个已编译的mod_wsgi模块的一个实例加载到Apache中。

你用python2.7安装mod_wsgi,如果你现在系统defalut python是python 3.5,你可以重新安装mod_wsgi(对于ubuntu,我不知道如何重新安装centos,但你需要做的就是重新安装mod_wsgi与你的virtualenv使用python(必须是相同的安装):

sudo apt-get install libapache2-mod-wsgi-py3

如果你的系统defalut python不是python3.5,请从here下载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