Django部署:配置apache / mod_wsgi使用的正确python

我是新手使用基于Django的应用程序并尝试使用以下配置部署
django项目,这几乎与
django docs上给出的默认设置类似.

apache2.conf

# WSGI Configuration
WSGIDaemonProcess demo python-path=/home/inian/Documents/demo
WSGIProcessGroup demo

WSGIScriptAlias / /home/inian/Documents/demo/demo/wsgi.py process-group=demo

<Directory /home/inian/Documents/demo/demo>
<Files wsgi.py>
    Require all granted
</Files>
</Directory>

# Serving static files
Alias /static/ /home/inian/Documents/demo/static/

<Directory /home/inian/Documents/demo/static>
    Require all granted
</Directory>

当我启动apache服务器时,它正常启动但由于python版本不匹配,因此加载我的项目时出现运行时错误.

/var/log/apache2/error.log

[Sun Apr 10 20:38:16.165536 2016] [wsgi:warn] [pid 22959] mod_wsgi: Compiled for Python/2.7.11.
[Sun Apr 10 20:38:16.165551 2016] [wsgi:warn] [pid 22959] mod_wsgi: Runtime using Python/2.7.10.
[Sun Apr 10 20:38:16.166787 2016] [mpm_prefork:notice] [pid 22959] AH00163: Apache/2.4.7 (Ubuntu) OpenSSL/1.0.1f mod_wsgi/4.5.1 Python/2.7.10 configured -- resuming normal operations

我希望我的应用程序使用安装在位置/usr/local的版本为2.7.11的python,这是我用来编译和安装mod_wsgi的那个,但为了安全我还检查了/usr/bin/python -V它提供输出为Python 2.7.6.这可以用于两个问题:

>我如何指出apache从安装位置/usr/local/bin / python使用Python 2.7.11(我一直使用它作为服务器上所有内容的默认设置).
>我不记得曾经使用2.7.10安装或做任何事情,所以我不知道apache如何以及从何处加载和使用它.如果有人可以指导我,那么它也会很棒.

最佳答案 在针对特定Python安装编译mod_wsgi然后升级Python安装的情况下,这是一条警告消息.由于共享库的工作方式,它通常不重要.这记录在:

> http://modwsgi.readthedocs.org/en/develop/user-guides/installation-issues.html#python-patch-level-mismatch

在你的情况下,虽然问题是你的mod_wsgi没有针对Python的安装进行编译,但它是在运行时找到Python共享库.这可能会导致各种问题,其中一个问题是两个Python安装没有安装兼容的编译器标志集,例如Unicode字符宽度的问题.

基本上这个问题在我看来就像你从/usr/local中的Python安装源代码编译mod_wsgi,但是因为它的构建方式不正确,在运行时它会找到Python的共享库版本安装到/ usr.

有关如何在Linux系统上正确安装Python的大讨论,请阅读:

> http://blog.dscpl.com.au/2015/06/installing-custom-python-version-into.html

接下来,当您从源代码编译mod_wsgi时,请确保将LD_RUN_PATH环境变量设置为包含用于安装备用Python安装的Python共享库的库目录.该环境变量将允许mod_wsgi在运行时找到正确的库,而不使用/usr/lib中的版本.

您可以按照以下文档中的说明验证是否找到了错误的/正确的:

> http://modwsgi.readthedocs.org/en/develop/user-guides/checking-your-installation.html#python-shared-library

最后,一旦安装了mod_wsgi并找到了正确的共享库,您可能还必须在Apache配置中设置WSGIPythonHome指令,以便为运行时文件找到正确的Python安装.这在以下文档中描述:

> http://modwsgi.readthedocs.org/en/develop/user-guides/installation-issues.html#multiple-python-versions

点赞