django 部署在 apache2.4 python3.5(验证) 或 3.x(未验证) 版本出现错误.

16 篇文章 0 订阅
8 篇文章 0 订阅

首先感谢:@GrahamDumpleton
问题链接: github
一天时间。google了各种问题还是解决不了。百撕不得骑…咳咳
位于/var/log/apache2/error.log 出现

[Mon Jul 25 20:10:41.247841 2016] [wsgi:error] [pid 18106] mod_wsgi (pid=18106): Call to 'site.addsitedir()' failed for '(null)', stopping.
[Mon Jul 25 20:10:41.247874 2016] [wsgi:error] [pid 18106] mod_wsgi (pid=18106): Call to 'site.addsitedir()' failed for '/home/ling/django_project/lib/python3.5/site-packages'.
[Mon Jul 25 20:10:47.198769 2016] [wsgi:error] [pid 18106] mod_wsgi (pid=18106): Call to 'site.addsitedir()' failed for '(null)', stopping.
[Mon Jul 25 20:10:47.198806 2016] [wsgi:error] [pid 18106] mod_wsgi (pid=18106): Call to 'site.addsitedir()' failed for '/home/ling/django_project/lib/python3.5/site-packages'.
[Mon Jul 25 20:10:47.444672 2016] [wsgi:error] [pid 18106] [remote 192.168.1.2:52125] mod_wsgi (pid=18106): Target WSGI script '/home/ling/django_project/project/simple_project/simple_project/wsgi.py' cannot be loaded as Python module.
[Mon Jul 25 20:10:47.444717 2016] [wsgi:error] [pid 18106] [remote 192.168.1.2:52125] mod_wsgi (pid=18106): Exception occurred processing WSGI script '/home/ling/django_project/project/simple_project/simple_project/wsgi.py'.
。。。以下省略。。。因为上面的才是主要问题

The reference to debugging logging code was related to me commenting out logging code in mod_wsgi itself to verify where the issue was coming from, not disabling logging of your own.

Do be aware that any mod_wsgi packages shipped by Debian and Ubuntu are unsupported by Debian or Ubuntu and neither do I support them as they ship out of date ancient versions which are many releases behind. It is basically a myth that in a LTS version of those Linux distributions that they provide support. They don’t, they only do that for certain core packages and not the majority of stuff you might install. If you always use only system provided packages in the belief that they are supported, then the reality is that they aren’t.

As to a workaround, it depends on what paths you are trying to add. If you had something like:

WSGIDaemonProcess [...] python-path=/home/srittau/.virtualenvs/foo/lib/python3.5/site-packages:/home/srittau/foo/bar/pylibs

where one path is that related to a virtual environment, it isn’t the preferred way anyway. For a virtual environment you should use python-home option to specify the root of the virtual environment and not use python-path to specify the site-packages directory. Thus should use:

WSGIDaemonProcess [...] python-home=/home/srittau/.virtualenvs/foo python-path=/home/srittau/foo/bar/pylbs

Thus if the reason for two paths was because of one being the virtual environment, change it to the preferred setup and you should be good. If you are adding multiple directories for other reasons, this will not help and the only other option is to add the paths as part of the WSGI script file

总结

其实出现错误的原因就是不能使用python-path 路径来指定虚拟环境。
而应该使用python-home 路径否则无法正确通过虚拟环境来加载python 应用

附上我的配置作参考(内网下配置- 把192.168.1.2 改为域名):

<VirtualHost *:80>
    ServerName 192.168.1.2
    ServerAdmin zltningx@gmail.com

    Alias /media/ /home/ling/django_project/project/simple_project/media/
    Alias /static/ /home/ling/django_project/project/simple_project/blog/static/

    <Directory /home/ling/django_project/project/simple_project/media>
        Require all granted
    </Directory>

    <Directory /home/ling/django_project/project/simple_project/blog/static>
        Require all granted
    </Directory>

    WSGIScriptAlias / /home/ling/django_project/project/simple_project/simple_project/wsgi.py
    WSGIDaemonProcess 192.168.1.2 python-path=/home/ling/django_project/project/simple_project python-home=/home/ling/django_project/lib/python3.5/site-packages
    WSGIProcessGroup 192.168.1.2

    <Directory /home/ling/django_project/project/simple_project/simple_project>
    <Files wsgi.py>
        Require all granted
    </Files>
    </Directory>
</VirtualHost>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值