带有apache的wsgi无法读取通过管道安装的python软件包

时间:2019-04-18 11:34:53

标签: django python-2.7 apache mod-wsgi wsgi

我得到这个错误:

 sudo service apache2 restart :


    [Thu Apr 18 13:11:02.687353 2019] [mpm_event:notice] [pid 2135:tid 140232732096384] AH00491: caught SIGTERM, shutting down
    [Thu Apr 18 13:11:03.694739 2019] [ssl:warn] [pid 2300:tid 139990910658432] AH01909: ip-*.*.*.*.ec2.internal:443:0 server certificate does NOT include an ID which matches the server name
    [Thu Apr 18 13:11:03.702921 2019] [ssl:warn] [pid 2301:tid 139990910658432] AH01909: ip-*.*.*.*.ec2.internal:443:0 server certificate does NOT include an ID which matches the server name
    [Thu Apr 18 13:11:03.703014 2019] [wsgi:warn] [pid 2301:tid 139990910658432] mod_wsgi: Compiled for Python/2.7.11.
    [Thu Apr 18 13:11:03.703018 2019] [wsgi:warn] [pid 2301:tid 139990910658432] mod_wsgi: Runtime using Python/2.7.12.

然后我进入我们站点的域并进入/var/log/apache2/error.log:

[Thu Apr 18 13:11:03.703598 2019] [mpm_event:notice] [pid 2301:tid 139990910658432] AH00489: Apache/2.4.18 (Ubuntu) OpenSSL/1.0.2g mod_wsgi/4.3.0 Python/2.7.12 configured -- resuming normal operations
        [Thu Apr 18 13:11:03.703617 2019] [core:notice] [pid 2301:tid 139990910658432] AH00094: Command line: '/usr/sbin/apache2'
        [Thu Apr 18 13:11:10.014862 2019] [wsgi:error] [pid 2304:tid 139990600201984] err : No module named boto
        [Thu Apr 18 13:11:10.015214 2019] [wsgi:error] [pid 2304:tid 139990600201984] [client 81.218.184.134:30333] mod_wsgi (pid=2304): Target WSGI script '/home/ubuntu/path/to/my_project/src/my_project/wsgi.py' does not contain WSGI application 'application'.

我正在使用AWS EC2上的ubuntu 16.0.4 apache2和nod_wsgi,开始启动正在运行的项目(不是新项目)

在我的wsgi.py中打印异常:

No module named boto from 

try:
  application = get_wsgi_application()
except Exception as e:
    print "err : {}".format(e)

但我必须安装boto:

# pip freeze | grep boto
You are using pip version 8.1.1, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
boto==2.49.0
boto3==1.9.112
botocore==1.12.16

这是我根据https://docs.djangoproject.com/en/2.2/topics/install/配置的其他文件:     #cat /etc/apache2/mods-enabled/wsgi.load     LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

# cat /etc/apache2/mods-enabled/wsgi.conf
<IfModule mod_wsgi.c>


WSGIPassAuthorization on

WSGIScriptAlias / /home/ubuntu/path/to/wsgi.py
WSGIPythonPath  /home/ubuntu/path/to/my_project

<VirtualHost *:80>
        <Directory "/home/ubuntu/path/to//my_project/">
                Require all granted
        </Directory>
</VirtualHost>

 ..

</IfModule>

2 个答案:

答案 0 :(得分:1)

似乎您的site-packages指令中可能缺少WSGIPythonPath目录。我通常将python路径定义为WSGIDaemonProcess指令的一部分:

WSGIDaemonProcess example \
    display-name=example \
    processes=2 threads=20 \
    maximum-requests=10000 \
    umask=0002 \
    python-path=${SRV}/www:${SRV}/src:${SRV}/venv/prod_142/lib/python2.7/site-packages \
    python-eggs=${SRV}/.python-eggs

WSGIScriptAlias / ${SRV}/www/example/wsgi.py  \
    process-group=example      \
    application-group=%{GLOBAL}

您可以在https://github.com/datakortet/dkbuild-apacheconf的自述文件中看到功能更全的虚拟主机定义(我是作者)。

答案 1 :(得分:0)

问题在于,并非所有python软件包都已安装,在安装了所有缺少的软件包后,网站可以正常工作